Math.round() converts from double to long, and from float to int, as an alternate to casting (which always truncates).

The suggestion to use DecimalFormat is an excellant one. For anything having to do with displaying data to the user, it makes sense since it converts the number into a string. The only time i wouldn't use it is if you need the numeric value of the converted number for an math-based algorithm. You could still use DecimalFormat but converting to string then back to a number is extra work. [ February 04, 2006: Message edited by: Scott Selikoff ]

This won't work. Math.round(double) rounds double to the nearest long. multiplying by .05 is equivalent to dividing by twenty. Quick calculations suggest, then that any I'll track the steps in this algorithm with a range of values: values from -10 to 9 *.05 -.5 to .45 Math.round 0 to 0 /.05 0 to 0 So anything between -10 and 9.9999 will be mapped to 0.

You want things to go to the nearest .05 - here's how one might go to the nearest .5.

Math.round(value * 2) /2

Now let's trace a few values:

I haven't checked whether it works for 1.5 itself, and you will need to make it apply to your situation a little more directly.