# VBA Int function: why Int(900/0.9) returns 999 and not 1000?



## gifariz (Dec 25, 2022)

In VBA, when using Int or Fix function, why Int(900/0.9) returns 999 and not 1000?
Is it because of Type precision or decimal-binary thing?
Now my workaround is using WorksheetFunction.RoundDown or WorksheetFunction.Quotient, but I want to know the reason for above problem and I also prefer not using worksheetfunction if possible.
Thanks


----------



## HongRu (Dec 25, 2022)

Interesting.
I want to know why, too.

Here is my test.
FYR.

```
Sub test()
    Dim NumVar
    NumVar = 900
    outcome = Int(NumVar / 0.9)
    Debug.Print "NumVar is " & outcome '1000
    
    Dim NumDouble As Double
    NumDouble = 900
    outcome = Int(NumDouble / 0.9)
    Debug.Print "NumDouble is " & outcome '999
    
    Dim NumInt As Integer
    NumInt = 900
    outcome = Int(NumInt / 0.9)
    Debug.Print "NumInt is " & outcome '999
End Sub
```


----------



## wclaw (Dec 25, 2022)

gifariz said:


> In VBA, when using Int or Fix function, why Int(900/0.9) returns 999 and not 1000?
> Is it because of Type precision or decimal-binary thing?
> Now my workaround is using WorksheetFunction.RoundDown or WorksheetFunction.Quotient, but I want to know the reason for above problem and I also prefer not using worksheetfunction if possible.
> Thanks


INT() neglect decimal point

try 
outcome = Application.RoundUp(NumVar / 0.9, 0)


----------



## Alex Blakenburg (Dec 26, 2022)

It a fairly well known issue caused by stroring numbers as a floating point.
Floating-point arithmetic may give inaccurate result in Excel - Office

One workaround is to use CDec in your formula

```
outcome = Int(*CDec*(NumDouble) / 0.9)
outcome = Int(*CDec*(NumInt) / 0.9)
```

If either number can be relied on as having 4 or less decimals than CCur will work too eg

```
outcome = Int(NumDouble / *CCur*(0.9))
    outcome = Int(NumInt / *CCur*(0.9))
```


----------



## gifariz (Dec 26, 2022)

Alex Blakenburg said:


> It a fairly well known issue caused by stroring numbers as a floating point.
> Floating-point arithmetic may give inaccurate result in Excel - Office
> 
> One workaround is to use CDec in your formula
> ...


Thank you!
I'm gonna use Int(CDec(NumDouble/NumDouble)), hopefully no more inaccurate result.


----------



## Alex Blakenburg (Dec 26, 2022)

Thanks for letting us know. Glad we could help.


----------

