1

i want to round off a double value to its nearest 0.05 in java. eg: 54.625 to 54.65

or

32.1885 to 32.19 etc.

meenakshi
  • 23
  • 1
  • 3

1 Answers1

1
double foo = 54.625;
foo = (int)(foo * 20.0 + 0.5) / 20.0;

This is quick and dirty - it doesn't handle negative numbers correctly, for instance. But for simple problems, it's a simple solution.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408