R
Raj
How do I round up a number to the nearest 0.05?
How do I round up a number to the nearest 0.05?
Peter Duniho said:
How do I round up a number to the nearest 0.05?
Raj said:Try out the solution with these numbers:
16.489 should return 16.49
6.66 should return 6.70
etc.,
None of the solution does this, i am sorry!
[...] To round-up-to the next 1/20 (unless it is already an exact
1/20), rather use
Math.Ceiling( 20*x ) / 20.0
None of the solution does this, i am sorry!
Try out the solution with these numbers:
16.489 should return 16.49
6.66 should return 6.70
etc.,
Arne said:The question was:
#How do I round up a number to the nearest 0.05?
16.489 rounded to nearest 0.05 is 16.50 and 6.66 rounded
to nearest 0.05 is 6.65.
At least according to normal understanding of rounding
to nearest 0.05.
I very much hope that my code do return those results. [...]
Arne said:The question was:
#How do I round up a number to the nearest 0.05?
True. Note the word "up" in the above sentence.
16.489 rounded to nearest 0.05 is 16.50 and 6.66 rounded
to nearest 0.05 is 6.65.
True. But, 6.66 rounded *UP* to the nearest 0.05 is 6.70.
At least according to normal understanding of rounding
to nearest 0.05.
I very much hope that my code do return those results. [...]
Your code works fine for the problem you were trying to solve. But I
believe you have misunderstood what the OP is asking for.