Rounding to nearest hudred

Just starting out? Need help? Post your questions and find answers here.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Rounding to nearest hudred

Post by vwidmer »

What would be best way to round to nearest hundred? or does anyone have code already?
Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Rounding to nearest hudred

Post by Josh »

Code: Select all

a.i = 349
Debug (a+50)/100*100

Code: Select all

a.d = 349
a = Round (a/100, #PB_Round_Nearest) * 100
Debug a
sorry for my bad english
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Rounding to nearest hudred

Post by vwidmer »

Josh wrote:

Code: Select all

a.i = 349
Debug (a+50)/100*100

Code: Select all

a.d = 349
a = Round (a/100, #PB_Round_Nearest) * 100
Debug a
Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Rounding to nearest hudred

Post by Josh »

Be careful with negative values in the first example. See also here:

viewtopic.php?f=4&t=73176
sorry for my bad english
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: Rounding to nearest hudred

Post by C87 »

How about:

Code: Select all

a = Int(35566*0.01)
Debug a
If it's falling over......just remember the computer is never wrong!
Post Reply