java - How to Round a BigDecimal Value to its nearest hundreths -


example:

public class round {      private static final bigdecimal twelve = new bigdecimal("12");     public static void main(string[] args) {          bigdecimal annualamt = new bigdecimal("55867.59");         bigdecimal monthlyamt = null;          monthlyamt = annualamt.divide(twelve, 0, roundingmode.half_up);         system.out.println(monthlyamt);     } } 

the above program output 4656. want round nearest hundredth 4700.

similarly 4235 --> 4200

to round given bigdecimal nearest hundred, use monthlyamt = monthlyamt.setscale(-2, roundingmode.half_even) (or substitute appropriate rounding mode).


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -