Question : ASP/VBScript subtraction problem

I am basically trying to subtract one value from another in some server side vbscript on a classic asp page, and I'm not getting the results which I require.

Examples:

309.99-310=-9.99999999999091E-03
9.99-10=-9.99999999999979E-03
1.885-1.884=1.00000000000011E-03

I have tried converting the variants to single and double format prior to and after the calcualtion, with no effect. The only way I have managed to get this to work correctly is to convert to currency, but surely this should not be necessary. It just makes no sense. Even if I break the program and perform the calculations within the watch list, using the actual numbers rather than variants, it still returns the same results, in double format.

Any help would be greatly appreciated.....

Answer : ASP/VBScript subtraction problem

>>I have tried converting the variants to single and double format prior to and after the calcualtion, with no effect. The only way I have managed to get this to work correctly is to convert to currency, but surely this should not be necessary. It just makes no sense. <<
It actually makes all the sense in the world:
Both single and double use IEEE format and as such are approximate numeric values (and have been that way for at least the last 25 years), they cannot represent all the values available, and is also the reason they have such a vast range.
Currency on the other hand is in fact stored as an integer that is why it is always exact.  It is returned offset by 10000 which explains the fact that it has a precision of 4 decimals.
Random Solutions  
 
programming4us programming4us