I need the following results:
10.17111 -> 10.17
10.17445 -> 10.18
I tried BigDecimal and DecimalFormat methods and RoundingMode class:
String value = "10.17111";
BigDecimal bd = new BigDecimal(value);
BigDecimal bdResult = bd.setScale(2, RoundingMode.UP);
String result = bdResult.toString();
System.out.println(result);
Print out = 10.18
Should be = 10.17
double ddd = 10.17111;
DecimalFormat d = new DecimalFormat("#.##");
d.setRoundingMode(RoundingMode.UP);
String outputResult = d.format(ddd).replace(',', '.');
System.out.println(outputResult);
Print out = 10.18
Should be = 10.17
And with BigDecimal:
String value2 = "10.17445";
Print out = 10.18
As I expected
And with DecimalFormat:
double ddd2 = 10.17445;
Print out = 10.17
Should be = 10.18