Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
input_row.column.scale(2,BigDecimal.ROUND_HALF_UP)
BigDecimal bd = new BigDecimal(2.437732);
BigDecimal bd2 = bd.setScale(2,BigDecimal.ROUND_HALF_UP);
System.out.println("bd2 = "+bd2);
Starting job test at 17:13 22/05/2014.
connecting to socket on port 3511
connected
bd2 = 2.44
disconnected
Job test ended at 17:13 22/05/2014.
If they are floats, you don't need to turn them into bigdecimals.
You could easily use Math.round().
I'll explain:
Var1 is type float.
Var1 = 2,539
Math.round(Var1) is 3
Var1 * 100 is 253,9
This means that Math.round(Var1 * 100) is 254
This also means that Math.round(Var1 * 100) / 100 is 2,54
So, if you want to round a float to 2 decimal places, do this:
Var2 = 2,54