Jump to content

Round up to nearest n. Simpler calculation?


This topic is 6823 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi all,

I have a need for a calculation that rounds up positive numbers to the nearest n, with n being equal to whatever value the user enters. I wrote a calc for it that seems to do precisely that but I just have this nagging feeling that it's "taking the long way around the barn". Can anyone simplify this?

Case (

roundValue * Int( Round( inputNumber;0 ) / roundValue ) > inputNumber ;

roundValue * Int( Round( inputNumber;0 ) / roundValue );

roundValue * Int( Round( inputNumber;0 ) / roundValue ) + roundValue)

See the attachment for more info.

Any help would be appreciated...thanks in advance!

RoundTest.zip

Link to comment
Share on other sites

To round up add 1/2 (0.5) to the number before rounding->

e.g. Round(123.456 ; 0) returns 123

Round(123.456 + 0.5; 0) returns 124

Mathematically, the standard is to round up for values >= x.5. So adding .5 forces any x.y to round up to x + 1.

Link to comment
Share on other sites

This topic is 6823 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.