![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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.. > > (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) >> Quote: Quote: >> wscript.echo 9.9 * 10 ^-3 >> Quote: Quote: >> quit |
My System Specs![]() |
![]() |
| Thread Tools | |
| |