fork 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. BigDecimal bd = new BigDecimal("4000.22");
  15.  
  16. System.out.println(bd.precision()-bd.scale());
  17.  
  18. }
  19. }
  20.  
Success #stdin #stdout 0.1s 55212KB
stdin
Standard input is empty
stdout
4