Aug 30, 2002 #1 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
Aug 30, 2002 1 #2 darrellblackhawk Programmer Joined Aug 30, 2002 Messages 846 Location US 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 Upvote 0 Downvote
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
Aug 30, 2002 #3 SnyAc Programmer Joined Jul 25, 2001 Messages 272 Location US a=21 r=int(a/5)+5 this will work if you are rounding up Upvote 0 Downvote
Aug 30, 2002 #4 darrellblackhawk Programmer Joined Aug 30, 2002 Messages 846 Location US 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 Upvote 0 Downvote
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
Aug 30, 2002 #5 DSummZZZ Programmer Joined Oct 24, 2000 Messages 4,250 Location US 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. Upvote 0 Downvote
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.
Aug 30, 2002 1 #6 ramani Programmer Joined Mar 15, 2001 Messages 4,336 Location AE 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 Upvote 0 Downvote
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
Aug 30, 2002 #7 darrellblackhawk Programmer Joined Aug 30, 2002 Messages 846 Location US Ramani gets my star for simplicity. I guess I got the star for being obtuse Darrell Upvote 0 Downvote