Rounding a float to two decimal places

by raja 2010-01-28 15:58:53


The following code is one of the ways to round a float value to two decimal places.


float avg = 1.23567f;
avg *= 100;
avg = (float)Math.round(avg)/100;
System.out.println(avg);


Tagged in:

1620
like
0
dislike
0
mail
flag

You must LOGIN to add comments