I can’t achieve rounding a float with the common 0.5 rule.
Let’s be precise… How may I make such rounds :
- x.x2 -> x.x
- x.x5 -> x.x (or x.x+1 would be good also)
- x.x6 -> x.x+1
So for example :
- 1.12 -> 1.1
-
1.22 -> 1.2
-
1.15 -> 1.1 (or 1.2 woudl be good also)
-
1.25 -> 1.2 (or 1.3 woudl be good also)
-
1.16 -> 1.2
- 1.26 -> 1.3
I tried those methods (perhaps in a wrong way) :
- NSNumberFormatter
- NSDecimalNumber
- …
But nothing can give that result. I always get some x.x99999999 results, or badly rounded ones (too high, to low, or on even numbers when the rounded number should come on the upper one).
Try this one: