2017-11-14 4 views
-1

10 진수 이상으로 3 개 이상의 값을 입력하면 아래의 코드에 오류가 발생합니다. 하지만 십진수에서 길이를 2에서 3으로 늘리고 싶습니다.소수점 이하 길이

나는 precisionValue.length()>2에서 precisionValue.length()>3으로 증가했습니다. 그러나 오류는 동일하게 유지됩니다.

 if (str != null && str.length() > 0) { 
     boolean month2 = validator.validateDecimal(str.trim()); 
     if (!month2) { 
      errors.rejectValue(MONTH2, "10005"); 
     } 
     if(str.contains(".")){ 
      String decValue = str.substring(0, str.indexOf(".")); 
      String precisionValue = str.substring(str.indexOf(".")+1); 
      if(decValue.length()>9) { 
       errors.rejectValue(MONTH2, "10035"); 
      } 
      if(precisionValue.length()>2) { 
       errors.rejectValue(MONTH2, "10038"); 
      } 
     } 
     else if(str.length()>9) { 
      errors.rejectValue(MONTH2, "10035"); 
     } 
      } 
+0

프로그래밍 언어를 언급하면 ​​마법사가됩니다. – JJJ

답변

0

나는 C#으로 가정하고 구문을 수정했습니다. 역순으로 프로그래밍 언어를 얻을 수 있습니다. 10 진수 뒤에 3 자리 이상을 갖는 문자열 형식의 숫자를 선택하면 errors.rejectValue (month2, "10038");로 이동해야합니다. 코드 라인과 예상대로 작동하고 있습니다. 나는 당신의 문제를 완전히 이해할 수 없다.

  string str = "1.2345"; 
      if (str != null && str.Length > 0) 
      { 
       bool month2 = validator.validateDecimal(str.Trim()); 
       if (!month2) 
       { 
        errors.rejectValue(month2, "10005"); 
       } 
       if (str.Contains(".")) 
       { 
        String decValue = str.Substring(0, str.IndexOf(".")); 
        String precisionValue = str.Substring(str.IndexOf(".") + 1); 
        if (decValue.Length > 9) 
        { 
         errors.rejectValue(month2, "10035"); 
        } 
        if (precisionValue.Length > 3) 
        { 
         errors.rejectValue(month2, "10038"); 
        } 
       } 
       else if (str.Length > 9) 
       { 
        errors.rejectValue(month2, "10035"); 
       } 
      }