ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function Int (https://www.excelbanter.com/excel-programming/380224-function-int.html)

bcar

Function Int
 
Hi all,

I'm surprise by this result on excel( 2000, 2002, XP ) (win200, XP)

sub test()
Dim x as Long

x = Int(37.7266 * 10000)
' x = 377265
' I hope x = 377266

' but for :
x = int(37.7263 * 10000)
' I have x = 377263
end sub

In fact 37.7263 give expected result, 37.7264, no, 37.7265,
ok and so on...
Does somebody have an explanation ?

John Bundy

Function Int
 
Take out the Int stuff and it should be fine:

Sub test()
Dim x As Long

x = 37.7266 * 10000
' x = 377265
' I hope x = 377266

' but for :
x = 37.7263 * 10000
' I have x = 377263


--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"bcar" wrote:

Hi all,

I'm surprise by this result on excel( 2000, 2002, XP ) (win200, XP)

sub test()
Dim x as Long

x = Int(37.7266 * 10000)
' x = 377265
' I hope x = 377266

' but for :
x = int(37.7263 * 10000)
' I have x = 377263
end sub

In fact 37.7263 give expected result, 37.7264, no, 37.7265,
ok and so on...
Does somebody have an explanation ?


bcar

Function Int
 
John Bundy a écrit :
Take out the Int stuff and it should be fine:

Sub test()
Dim x As Long

x = 37.7266 * 10000
' x = 377265
' I hope x = 377266

' but for :
x = 37.7263 * 10000
' I have x = 377263


no because it's an expression and it's possible to have more than 4
decimals numbers.
the complete expression is :
x = y * 10000 - Int(y * 10000)
I know it's posssible to do x = y - round(y, 4) or to do :
tmp = y * 10000
x = tmp - Int(tmp)
The 2 solution work fine, but I don't want a solution, I'm surprised by
the result and I search an explanation

Thanks


Bob Phillips

Function Int
 
http://tinyurl.com/y4g5qg

or

http://tinyurl.com/wkmvr

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"bcar" wrote in message
...
John Bundy a écrit :
Take out the Int stuff and it should be fine:

Sub test()
Dim x As Long

x = 37.7266 * 10000
' x = 377265
' I hope x = 377266

' but for :
x = 37.7263 * 10000
' I have x = 377263


no because it's an expression and it's possible to have more than 4
decimals numbers.
the complete expression is :
x = y * 10000 - Int(y * 10000)
I know it's posssible to do x = y - round(y, 4) or to do :
tmp = y * 10000
x = tmp - Int(tmp)
The 2 solution work fine, but I don't want a solution, I'm surprised by
the result and I search an explanation

Thanks





All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com