fork(58) download
  1. import java.math.BigDecimal;
  2.  
  3. class DecimalTest {
  4.  
  5. static int integerDigits(BigDecimal n) {
  6. return n.signum() == 0 ? 1 : n.precision() - n.scale();
  7. }
  8.  
  9. static void check(BigDecimal n) {
  10. System.out.println(n + " : " + integerDigits(n));
  11. }
  12.  
  13. static public void main(String[] args) {
  14. check(new BigDecimal("999999.99999"));
  15. check(new BigDecimal("999999.999"));
  16. check(new BigDecimal("999999.9"));
  17. check(new BigDecimal("999999"));
  18. check(new BigDecimal("-999999"));
  19. check(new BigDecimal("100"));
  20. check(new BigDecimal("100.000"));
  21. check(new BigDecimal("1234567890"));
  22. check(new BigDecimal("0"));
  23. check(new BigDecimal("0.0000"));
  24. }
  25. }
  26.  
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
999999.99999 : 6
999999.999 : 6
999999.9 : 6
999999 : 6
-999999 : 6
100 : 3
100.000 : 3
1234567890 : 10
0 : 1
0.0000 : 1