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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding explained cont... 2

Status
Not open for further replies.

godfreyw

Programmer
Joined
Aug 30, 2002
Messages
2
Location
US
I am trying to round 23 to 25
or 21 to 25

nearest 5 or 10
 
godfreyw :

Here's a tricky one for those who want to figure it out:
(23 can be a variable of course)

? int(val(left(allt(str(23)),len(allt(str(23)))-1))) * 10 + iif(int(val(right(allt(str(23)),1))) <= 5,5,10)

changing <= to <, rounds all units below 5 to 5 and 5 or greater to 10.

( Haven't worked it for real numbers. Will make it more complex :-) )
Darrell
 
a=21

r=int(a/5)+5

this will work if you are rounding up
 
SnyAc:

Maybe I'm missing something ( it wouldn't be the 1st time :-)), but,

a=21
r=int(a/5)+5 doesn't work.

r will return 9.

Darrell
 
Here's an ugly one:

STORE 23 TO num

iif(num % 10 = 0, num, ;
iif(num % 10 < 6, num - (num % 10) + 5, ;
iif(num % 10 > 5 , num - (num % 10) + 10, 999999999)))
Dave S.
 
HI

You question is rounding..
? ROUND(myNumber/5,0)*5 gives rounded to 5

But taking 21 to 25 is different..

This is CEILING(myNumber/5)*5

If you want 24 to 20.. then..
? FLOOR(myNumber/5)*5

Hope this helps you :-) ramani :-)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani gets my star for simplicity. I guess I got the star for being obtuse :-)

Darrell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top