Rounding float for android -
i want round float given precision. example:
0,6667 0,67 0,004 0,00 0,328 0,33
i know can round float integer, example:
0,06 0
is there way achieve this?
do need rounding display or calculations?
if it's display can use this:
decimalformat df = new decimalformat("##.00"); float f = (float) 4.234432; system.out.println(df.format(f));
for calculations, this:
float f = (float) 4.234432; bigdecimal bd = new bigdecimal(f); bd = bd.setscale(2, roundingmode.half_up); f = bd.floatvalue();
Comments
Post a Comment