Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - Re: HELP: 5.01 - 5 = 9.9????

Reply
 
Old 06-11-2009   #1 (permalink)
ekkehard.horner
Guest


 
 

Re: HELP: 5.01 - 5 = 9.9????

PadovaBoy (ovvero Giovanni) schrieb:
Quote:

> Hi at all.
> I have a "curious" problem with Asp classic (vbscript engine) in IIS6 (ms
> server 2003) ad IIS7 (ms vista):
>
> This is the test:
>
> dim a,b
> a = CDbl(5.01)
> b = CDbl(5.00)
> Response.Write a & " - "&b&" = "& ( a - b) & "<br>"
> c = CDbl ( a - b) 'another try..
> Response.Write c & "<br>"
>
> The results are:
> 5,01 - 5 = 9,99999999999979E-03
> 9,99999999999979E-03
>
> Why? At my home 5.01 - 5 = 0.01 not 9,9...
>
> Tnx for any suggestions..
>
>
Two problems:

(1) the computer's numbers are different from the mathematical concept
of numbers. See (e.g.)

http://en.wikipedia.org/wiki/Floating_point

for the how and why. In your case the exact result 0.01 is approximated
by 9,99999999999979 * 10 ^ -3.

(2) use FormatNumber if you want to display numbers to the user

Quote:
Quote:

>> a = 5.01 : b = 5.0
>> wscript.echo typename(a), typename(b), a, b, a-b, formatnumber(a-b,6)
>>
Double Double 5,01 5 9,99999999999979E-03 0,010000
Quote:
Quote:

>> wscript.echo 9.9 * 10 ^-3
>>
0,0099
Quote:
Quote:

>> quit

My System SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46