fork(1) download
  1. import java.math.*;
  2. class Ideone
  3. {
  4. public static void main (String[] args) throws java.lang.Exception
  5. {
  6. checkNoOfDigitsVal(new BigDecimal("999999.9999"));
  7. checkNoOfDigitsVal(new BigDecimal("9999999.9999"));
  8. checkNoOfDigitsVal(new BigDecimal("99999.9999"));
  9. }
  10.  
  11. public static void checkNoOfDigitsVal(BigDecimal bigDecVal) {
  12. String str = bigDecVal.toString();
  13. int wholeNumberLength = str.split("\\.")[0].length();
  14. if (wholeNumberLength <= 6) {
  15. System.out.println("correct size insert into DB: " + wholeNumberLength + " (" + str + ")");
  16. } else {
  17. System.out.println("Incorrect size insert cancel: " + wholeNumberLength + " (" + str + ")");
  18. }
  19. }
  20. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
correct size insert into DB: 6 (999999.9999)
Incorrect size insert cancel: 7 (9999999.9999)
correct size insert into DB: 5 (99999.9999)