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

Always ROUND UP?????

Status
Not open for further replies.

pwel

Programmer
Aug 18, 1999
79
GB
This is probably simple, but the answer escapes me! I want to use the Round() function, but always round the number up??

i.e. myvar = Round(3.3) I need to equal 4 ?

Any ideas?

Cheers in advance.

PW.
 
add .5 to the value you are rounding up first:


value = value + .5
myvar = Round(value)
 
actually, it needs a little bit more, since if it's already a whole number, you don't want to round up....

so maybe something like:

roundValue = value + .5
If value <> Int(roundValue) Then
myvar = Round(roundValue)
Else
myvar = roundValue
End If
 
okay, sorry about all that, i just tested it, and came across a few bugs..... first of all, the Round() function will round up for an even .5 for odd numbers and down for even numbers. i don't understand the logic of that, but that's how it works... so i added the following compares to allow for that:

value = yournumber
If Int(value) Mod 2 <> 0 Then
roundValue = value + .49
Else
roundValue = value + .5
End If
If value <> Int(roundValue) Then
myvar = Round(roundValue, 0)
Else
myvar = value
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top