Re: adCurrency problem in ASP

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: 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: Field format - Access 2003
    ... Currency field. ... You probably are trying to use a number field with the type set to Long and those two types of number fields only hold integers. ... Access MVP 2002-2005, 2007-2008 ... I tried making the fields general number with 2 decimal places, and I can type the decimals in, but then it seems to round up/down whatever I type and show the value as a whole number. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Display 3 decimals in combo box
    ... In the RowSource SQL, try using the ... format function specifying 3 decimal places e.g. ... the currency field displays only as 2 decimals. ...
    (microsoft.public.access.forms)
  • 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)

Loading