Re: adCurrency problem in ASP

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Evertjan. (exjxw.hannivoort_at_interxnl.net)
Date: 03/27/05


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)


Relevant Pages

  • Re: adCurrency problem in ASP
    ... One of the columns in a currency field. ... Non integer values are usually stored in a binary format. ... decimals, either store it as a integer [in cents, if we are talking ... VBscript and Jscript do not use BCD. ...
    (microsoft.public.inetserver.asp.general)
  • Re: Currency Field
    ... "John W. Vinson" wrote: ... I have a form with a currency field that has 5 decimal points. ... The Currency datatype in Access is a scaled large integer, ... and a Scale of 5 to store five decimals. ...
    (microsoft.public.access.forms)
  • Re: Currency Field
    ... I have a form with a currency field that has 5 decimal points. ... rounds up when I do not want it to. ... The Currency datatype in Access is a scaled large integer, ... and a Scale of 5 to store five decimals. ...
    (microsoft.public.access.forms)
  • Re: Renumbering a field value in a set of records
    ... Change your numbering scheme to use numbers with decimals - in Access I ... would probably use the currency field if I were using the numbers to link ... Therefore I need to renumber record 6 - 10 so that the revised line number ... I guess this is a simple update query, but I'm not so advanced at the ...
    (microsoft.public.access.queries)
  • Re: Rounding issue
    ... I want to do financial calculations (nothing special, ... With "as they are" I suppose you mean in the decimal system. ... Perl does not provide BCD natively (Binary Coded Decimals; ...
    (comp.lang.perl.misc)