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

How do i simulate the math FLOOR operation?

Status
Not open for further replies.

kingpoop

Programmer
Sep 11, 2001
7
US
Does anyone know how to simulate the
Floor function in VBScript?

thx
 
Isn't that a Min function.
On Error Resume next
L = Ubound(ary)
if Err.Number <> 0 then L = -1
On Error Goto 0
If L >=0 then
floor = ary(0)
For I = 1 t0 Ubound(ary)
if ary(I) < floor then floor = ary(I)
End if
End If Compare Code (Text)
Generate Sort in VB or VBScript
 
In VBScript, Int( ) is the same as Iverson's floor( ), while Fix( ) is more what people think they'll get when they use Int( ).

Int(3.2) is 3
Fix(3.2) is 3

Int(-3.2) is -4
Fix(-3.2) is -3


Personally I have seen many cases where this misguided definition of Int( ) (and its unsuspecting use) has caused bug after bug. I can't think of one appropriate use for Iverson's floor( ), but we're stuck with it as a pitfall awaiting unwary VB and VBScript programmers.

So the question really shouldn't be how to use floor( ), but instead how to avoid it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top