How to achieve functionality similar to excel's Roundup() in java?
for example - how to round 0.3102 to 0.4 in java ?
double r =0.3102;
BigDecimal bd = new BigDecimal(r);
bd = bd.setScale(1,BigDecimal.ROUND_UP);
r = bd.doubleValue();
System.out.println(r);
BigDecimal can help in achieving this.
for example-
// new BigDecimal(<your-number>).setScale(<scale-value>, BigDecimal.ROUND_UP))
result = new BigDecimal(0.3105).setScale(1, BigDecimal.ROUND_UP));
// result = 0.4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With