I am using decimalformat to format a value to 2 decimal places
Ex : 200.0075 --> 200.00
Ex: 200.0050 --> 200.00
The code i am using is :
DecimalFormat df = new DecimalFormat("#.##")
Problem is
String value = df.format(200.0075) gives 200.01
and
String value = df.format(200.0050) gives 200.00
How can i get only 2 decimal places using deciamlformat in java.
You’re seeing this rounding behavior because the default rounding mode for
DecimalFormatisHALF_EVEN. UseRoundingMode.DOWNinstead.