![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Function Int fails ? Hi to all, this is the code in my file test.vbs : Dim Result Result = (2170.12 / 9.08) ' is 239 msgbox("(2170.12 / 9.08) =**" & Result & "**") msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok Result = (2179.2 / 9.08) ' is 240 msgbox("(2179.2 / 9.08) =**" & Result & "**") msgbox("Int(Result) =**" & Int(Result) & "**") ' Error! Why 239 ? Result = (2188.28 / 9.08) ' is 241 msgbox("(2188.28 / 9.08) =**" & Result & "**") msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok Any ideas? Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Function Int fails ? Int rounds the number. If you switch the slashes to backslashes you'll get yet another result. That's what's supposed to happen. An integer is a whole number. Quote: > this is the code in my file test.vbs : > > Dim Result > > Result = (2170.12 / 9.08) ' is 239 > msgbox("(2170.12 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok > > Result = (2179.2 / 9.08) ' is 240 > msgbox("(2179.2 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Error! Why 239 ? > > Result = (2188.28 / 9.08) ' is 241 > msgbox("(2188.28 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok > > > Any ideas? > Thanks! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Function Int fails ? <massimoxr1@xxxxxx> wrote in message news:ac348705-c661-43f1-89ce-96f49507f88a@xxxxxx Quote: > Hi to all, > this is the code in my file test.vbs : > > Dim Result > > Result = (2170.12 / 9.08) ' is 239 > msgbox("(2170.12 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok > > Result = (2179.2 / 9.08) ' is 240 > msgbox("(2179.2 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Error! Why 239 ? > > Result = (2188.28 / 9.08) ' is 241 > msgbox("(2188.28 / 9.08) =**" & Result & "**") > msgbox("Int(Result) =**" & Int(Result) & "**") ' Ok > > > Any ideas? > Thanks! is often inexact. Internally, the result is closer to 239.9999999999999. Note that Int((2179.2 / 9.08) + .0000000000001) is 240. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Function Int fails ? ok, and what about the function CInt ? Result = (2179.2 / 9.08) ' is 240 msgbox("(2179.2 / 9.08) =**" & Result & "**") msgbox("CInt(Result) =**" & CInt(Result) & "**") 'returs 240 CInt seems to return the right value. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Function Int fails ? massimoxr1@xxxxxx schrieb: Quote: > ok, and what about the function CInt ? > > Result = (2179.2 / 9.08) ' is 240 > msgbox("(2179.2 / 9.08) =**" & Result & "**") > msgbox("CInt(Result) =**" & CInt(Result) & "**") 'returs 240 > > > CInt seems to return the right value. CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Function Int fails ? <massimoxr1@xxxxxx> wrote in message news:4e4f6b9d-5adc-439a-8dac-3b4de1686c0b@xxxxxx Quote: > ok, and what about the function CInt ? > > Result = (2179.2 / 9.08) ' is 240 > msgbox("(2179.2 / 9.08) =**" & Result & "**") > msgbox("CInt(Result) =**" & CInt(Result) & "**") 'returs 240 > > > CInt seems to return the right value. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Function Int fails ? "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:uX0YMH$HJHA.4936@xxxxxx Quote: > > <massimoxr1@xxxxxx> wrote in message > news:4e4f6b9d-5adc-439a-8dac-3b4de1686c0b@xxxxxx Quote: >> ok, and what about the function CInt ? >> >> Result = (2179.2 / 9.08) ' is 240 >> msgbox("(2179.2 / 9.08) =**" & Result & "**") >> msgbox("CInt(Result) =**" & CInt(Result) & "**") 'returs 240 >> >> >> CInt seems to return the right value. > CInt rounds, while Int (and also Fix) does not. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > must be datatype integer). The Int and Fix functions can handle any numeric values. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| function to delete a function | PowerShell | |||
| Complete PC Backup fails, restore fails differently! | Vista performance & maintenance | |||
| Contact List Fails to Function | Vista mail | |||
| Windows Explorer fails and fails and fails... | Vista General | |||
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | PowerShell | |||