Re: adCurrency problem in ASP
From: Evertjan. (exjxw.hannivoort_at_interxnl.net)
Date: 03/27/05
- Next message: Bob Barrows [MVP]: "Re: Storing objects in Session Variables - exactly why not?"
- Previous message: What-a-Tool: "Re: Help with command object parameters query?"
- In reply to: Jonathan Dodds: "adCurrency problem in ASP"
- Next in thread: Jonathan Dodds: "Re: adCurrency problem in ASP"
- Reply: Jonathan Dodds: "Re: adCurrency problem in ASP"
- Messages sorted by: [ date ] [ thread ]
Date: 27 Mar 2005 10:59:40 GMT
Jonathan Dodds wrote on 27 mrt 2005 in
microsoft.public.inetserver.asp.general:
> I'm using ADO from an ASP 3.0 page written in JScript to query a database
> table in SQL Server 2000. One of the columns in a currency field.
>
> Instead of retrieving a value of 1095.60 like I expect, I'm getting
> 1095.6000000000001 instead.
>
[..]
>
> Am I doing something wrong here?
Yes you do.
What is wrong is your expectation.
Non integer values are usually stored in a binary format.
Just like 1/3 cannot be exactly stored in a decimal format,
many decimal fractions cannot be stored in a binary form,
without an error in the least significant bit(s).
The back conversion to decimal will not always result in the same
error nullified.
So if you want to represent a numberic value with a fixed number of
decimals, either store it as a integer [in cents, if we are talking
currency] or have a good rounding off algoritm.
btw: Some Basic interpreters build by Bill Gates around 1984
used BCD [binary coded decimal] as a standard number coding method.
There your problem would not arise. VBscript and Jscript do not use BCD.
-- Evertjan. The Netherlands. (Replace all crosses with dots in my emailaddress)
- Next message: Bob Barrows [MVP]: "Re: Storing objects in Session Variables - exactly why not?"
- Previous message: What-a-Tool: "Re: Help with command object parameters query?"
- In reply to: Jonathan Dodds: "adCurrency problem in ASP"
- Next in thread: Jonathan Dodds: "Re: adCurrency problem in ASP"
- Reply: Jonathan Dodds: "Re: adCurrency problem in ASP"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|