Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

round to nearest 5 1

Status
Not open for further replies.

Jami

Programmer
Jul 18, 2000
54
US
Hi all,
I have a value with 2 decimals, say 21.67, that I would like to round to the nearest integer of 5. Thus, it would become 20.00. Could anyone point me in the right direction?
Thanks much!
Jami
 
hi Jami

Glad to help.

The following 3 operations should give you the closest integer in increments of 5 for any X.

First set X. Then divide by your block factor. Take the result and round it to the closest integer. Take that result and multiply it by your block factor.

<CFSCRIPT>
x = 21.67;
x.div = x/5;
// x.div = 4.334
x.round = round(x.div);
// x.round = 4
x.closest = x.round * 5;
// x.closest = 20
</CFSCRIPT>

hope that works for you
 
Hey,
That was perfect! Thanks so much!
Jami
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top