Fix Function |
Microsoft.VisualBasic.Conversion
Fix( number )
A number whose integer portion is to be returned
A number of the same data type as number whose value is the integer portion of number
For nonnegative numbers , Fix returns the floor of the number (the largest integer less than or equal to number ).
For negative numbers, Fix returns the ceiling of the number (the smallest integer greater than or equal to number ).
If number is Nothing , Fix returns Nothing .
The operation of Int and Fix are identical when dealing with positive numbers: numbers are rounded down to the next lowest whole number. For example, both Int(3.14) and Fix(3.14) return 3.
If number is negative, Fix removes its fractional part, thereby returning the next greater whole number. For example, Fix(-3.667) returns -3. This contrasts with Int , which returns the negative integer less than or equal to number (or -4, in the case of our example).
The function returns the same data type as was passed to it.
Sub TestFix( ) Dim dblTest As Double Dim objTest As Object dblTest = -100.9353 objTest = Fix(dblTest) ' returns -100 Console.WriteLine(objTest & " " & TypeName(objTest)) dblTest = 100.9353 objTest = Fix(dblTest) 'returns 100 Console.WriteLine(objTest & " " & TypeName(objTest)) End Sub
Fix does not round number to the nearest whole number; it simply removes the fractional part of number . Therefore, the integer returned by Fix will be the nearest whole number less than (or greater than, if the number is negative) the number passed to the function.
Int Function, Round Function