# Int (VB6) equivalent in Xojo.

I remember that existed a function in VB6 called “Int” that returns the integer part of a number, example:

This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8) ’ Returns 99.
MyNumber = Fix(99.8) ’ Returns 99.

MyNumber = Int(-99.8) ’ Returns -100.
MyNumber = Fix(-99.8) ’ Returns -99.

I know about Round but It get only the number without decimals.

Any suggestions?

Have you looked at Floor, Ceiling and Round?

``` dim I as integer dim R as single ' or whatever else you want I = R \\ 1```

warning: I did not test this in the IDE.

``` dim I as integer dim R as single ' or whatever else you want I = R \\ 1```

warning: I did not test this in the IDE.[/quote]
I gonna check it

I’m watching that Ceil is like that I’m looking for

I don’t remember that int(-99.8) returned -100. If I recall correctly, it returned -99. I may be wrong, it’s been a while since I used that in VB6.

In any case, the code I suggested should return just the integer part of the number, disregarding the decimal part, regardless of sign.

edit: fix() does what my code does.

[quote=228628:@Louis Desjardins]I don’t remember that int(-99.8) returned -100. If I recall correctly, it returned -99. I may be wrong, it’s been a while since I used that in VB6.

In any case, the code I suggested should return just the integer part of the number, disregarding the decimal part, regardless of sign.

edit: fix() does what my code does.[/quote]

Indeed Int() is more like Floor().

https://msdn.microsoft.com/en-us/library/xh29swte(v=vs.90).aspx

[quote=228643:@Michel Bujardet]Indeed Int() is more like Floor().

https://msdn.microsoft.com/en-us/library/xh29swte(v=vs.90).aspx[/quote]
YEAHHHHHHH! Exactly you are right!!! Floor is more like Int.

I’m Using this to generate an Algorithm and the result is exactly as the original with Floor instead of Ceil.

ROOUND rounds to the closest integer so it might be what your looking for.

No. Round will return 100 for 99.8 which is not all what Int() does in VB6. Int() will return 99.

Assigning a floating point number to an Integer type will truncate the fractional part without any rounding.

``MyNumber = 99.8 ' Returns 99.``

Gerardo,

In your first post you showed examples with positive an negative numbers.
Although I also came from VB6 I don’t remember very well how it worked, but if you want to deal with positive an negative numbers probably you will have to use more than one function: Floor, Ceil or Round. You will have to create your own function.