java - Rounding Off For a Cell -
using following code trying round off double value nearest whole number eg 2.3 2.0 ,2.6 3.0.but if pass value 2.5 per math.round function should return 3 getting output of 2
private static void adddata(table b) throws exception { font font = new font(color.black); cell cell = null; double value = 143.567; cell = new cell(new phrase(roundoffvalue(value), font)); cell.sethorizontalalignment(element.align_center); table.addcell(cell); } public static string roundoffvalue(double value ) { return string.valueof( new float( math.round(value))); }
math#round()
round 2.5 3. docs state:
returns closest {@code long} argument, ties rounding positive infinity.
// prints 3. system.out.println(string.valueof(math.round(2.5d))); // prints 144. system.out.println(string.valueof(math.round(143.567)));
Comments
Post a Comment