4

I need to round a float to the nearest .5, for example:

1.1 = 1
1.5 = 1.5
1.6 = 1.5
1.8 = 2

and so on. I really don't know how to do it. Any help would be greatly appreciated.

Aleph72
  • 877
  • 1
  • 13
  • 40

1 Answers1

9

For positive numbers Multiply by 2, add 0.5, truncate, divide by 2.

Michael Dorgan
  • 12,453
  • 3
  • 31
  • 61