Showing posts with label CINT functions. Show all posts
Showing posts with label CINT functions. Show all posts

Wednesday, 30 November 2011

Vb Scripts: Round, Int and Fix & CINT functions

Round:
Returns a number rounded to a specified number of decimal places The following example uses the Round function to round a number to two decimal places: Dim MyVar, pi pi = 3.14159 MyVar = Round(pi, 2) ‘ MyVar contains
Int and Fix functions:
Returns the integer portion of a number. Fix(number) is equivalent to: Sgn(number) * Int(Abs(number)) The following examples illustrate how the Int and Fix functions return integer portions of numbers: MyNumber = Int(99.8) ‘ Returns 99. MyNumber = Fix(99.2) ‘ Returns 99. MyNumber = Int(-99.8) ‘ Returns -100. MyNumber = Fix(-99.8) ‘ Returns -99. MyNumber = Int(-99.2) ‘ Returns -100. MyNumber = Fix(-99.2) ‘ Returns -99.
CINT:
Returns an expression that has been converted to a Variant of subtype Integer The following example uses the CInt function to convert a value to an Integer: Dim MyDouble, MyInt MyDouble = 2345.5678 ‘ MyDouble is a Double. MyInt = CInt(MyDouble) ‘ MyInt contains 2346. Note CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.