Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)
Avatar of Sathish David  Kumar N

ASKER

Thanks for your support