Page 1 of 1

Rounding to nearest hudred

Posted: Thu Jul 11, 2019 8:38 pm
by vwidmer
What would be best way to round to nearest hundred? or does anyone have code already?
Thanks

Re: Rounding to nearest hudred

Posted: Thu Jul 11, 2019 9:04 pm
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

Re: Rounding to nearest hudred

Posted: Thu Jul 11, 2019 9:36 pm
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

Re: Rounding to nearest hudred

Posted: Fri Jul 12, 2019 7:24 am
by Josh
Be careful with negative values in the first example. See also here:

viewtopic.php?f=4&t=73176

Re: Rounding to nearest hudred

Posted: Fri Jul 12, 2019 7:49 am
by C87
How about:

Code: Select all

a = Int(35566*0.01)
Debug a