We help IT Professionals succeed at work.

Why BigDecimal.Sclae() not not working for non decimal value

Sathish David  Kumar N
on
124 Views
Last Modified: 2019-07-23
Why BigDecimal.Sclae() not not working for non decimal value

      public static void main(String[] args) {
            // TODO Auto-generated method stub
            formatBD(2,new BigDecimal(10));
            formatBD(2,new BigDecimal(10.0567));
            formatBD(2,new BigDecimal(10.05));
            formatBD(2,new BigDecimal(10.000023));
      }
      
      public static void   formatBD(int sca,BigDecimal amount)
      {
            System.out.println(amount.scale() > 0 ? amount.setScale(2, BigDecimal.ROUND_CEILING) : amount);
      }
}

Output :10
10.06
10.06
10.01
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)
CERTIFIED EXPERT

Author

Commented:
Thanks for your support