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

Simple Rounding

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
How do you round up in vbscript? I am looking to do what would be math.ceil() in javascript - you know rounding up no matter what the decimal is

thanks
 
take a look at this thread
thread329-329218

also, if all you want to do is round something vbscript round function will do this fairly simple
syntax
Round(expression[, numdecimalplaces])
Dim var1, var2
var2 = 999.9
var1 = Round(var2, 0) ' var1 = 1000

You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Hello,

Math.floor() <=== int()
Math.ceil() <=== custom_function_roundup
Math.ceil() <===> Math.floor()+1
hence
custom_function_roundup=int()+1

regards
 
Always UP regardless of decimal? Use Int. Int always returns the &quot;first integer less than or equal to number&quot; so first make it negative, get INT value then reverse the sign again.

RoundUp = -Int(-dblIn)

From Docs
&quot;The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.&quot; Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Hello again.

Just to put the record straight. I've forgotten the obvious case where the number is already an integer, positive or negative.

Along this line, the custom_function_roundup() would be something like this:

Function custom_function_roundup(v)
If v<>Int(v) Then
custom_function_roundup=Int(v)+1
Else
custom_function_roundup=int(v)
End If
End Function

And of course the correspondance between Math.floor() and Math.ceil() contains this element as well.

regards
 
Terribly embarrassed. Some error of transmission had led me to believe failures in the submitting process. Wish the moderator can delete redundant submission.

-visitji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top