(Math.round(doubleValue*100))/100.0
Is there a better way to round decimals to 2 decimal places?
If you're interested in decimal places and therefore precise decimal values, you should typically be using java.math.BigDecimal
to start with. You can then use Decimal.round
or Decimal.setScale
to round according to your exact needs.
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