Fix Function

   
Fix Function

Class

Microsoft.VisualBasic.Conversion

Syntax

 Fix(   number   ) 
number (required; Double or any numeric expression)

A number whose integer portion is to be returned

Return Value

A number of the same data type as number whose value is the integer portion of number

Description

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 ).

Rules at a Glance

  • 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.

Example

 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 

Programming Tips and Gotchas

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.

See Also

Int Function, Round Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net