You do not need to guess what 0.35 means as
BigDecimal valDouble = new BigDecimal(0.35); System.out.println(valDouble);
prints
0.34999999999999997779553950749686919152736663818359375
This will be rounded to 1 decimal place of 0.3
You do not need to convert to String, you can use valueOf
BigDecimal valDouble = BigDecimal.valueOf(0.35); System.out.println(valDouble);
prints
0.35
To round half to one decimal place, you can use
double d = 0.35; double d1 = Math.round(d * 10) / 10.0; System.out.println(d1);
prints
0.4
Peter Lawrey Jul 06 2018-12-12T00: 00Z
source share