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

rounding numbers

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
Now I am sure this is very simple but..........

how do I round a number up?
ie 3.11 to 4

cheers
 
great, is there any way to do it in vbscript. ie if there is a decimal remove decimal and add 1??
 
Hello,
First my guess was FormatNumber function in VbScript
but no, it rounds the same way as Round.

Then I found very nice function Int
which do the task of getting only whole part of a decimal.
and you could write a VBScript function something like:

function ceil(val)
val = Int(val)
ceil = val + 1
end function

Take care of negative numbers :)
D.
 
' Handle neagtive numbers
' Use \ (integer division)
If Not (X \ 1 = X) then ' if there is decimal
if X < 0 then
X = (X - 1) \ 1
Else
X = (X + 1) \ 1 ' add 1 and truncate
End If
End if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top