Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Round to nearest 5
Message
From
25/01/2005 08:34:52
 
 
To
25/01/2005 08:05:22
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00980330
Message ID:
00980359
Views:
25
>I am surprised by the complexity of some of the other solutions you received. Simply divide by 5, round, and then multiply by 5 again.
>
>
>? round(x / 5, 0) * 5
>
>
>This method would also work for fractions, e.g., round to the nearest 5 cents: replace 5 with 0.05.
>
>To round always down or always up, replace round() with ceiling() or floor().
>
>AFAIK, there is no built-in function to round to the "nearest whatever".

Good solution. Just wanted to point out that ROUND() can take a negative number for the second parameter to round to a power of 10. That is:

ROUND(x, -1) rounds to the nearest 10
ROUND(x, -2) rounds to the nearest 100
...

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform