Re: adCurrency problem in ASP

From: Jonathan Dodds (NO_REPLY)
Date: 03/27/05


Date: Sun, 27 Mar 2005 14:50:51 -0500


"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9626842FB84E3eejj99@194.109.133.29...
> 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)
>

Why doesn't Query Analyzer display the decimal error? Is it rounding behind
my back?



Relevant Pages

  • RE: prePEP: Decimal data type
    ... > the rounding procedure to be used in computations involving Euros ... implementing a fixed number of decimal digits "after the decimal point" ... To convert from the euro to the national currency, ... currency should then be rounded to two decimals. ...
    (comp.lang.python)
  • Re: Round off
    ... rounding to two decimal places which necessarily gives a String. ... The OP asked about rounding a number to 2 decimals - not about converting it ... Number 3.5 is a multiple of ... FAQ 4.6 can be correspondingly changed. ...
    (comp.lang.javascript)
  • Re: Decimal
    ... It is even calculating the decimals ... You can see that by clicking on a cell you entered data in and looking at the formula bar... ... You can truncate off any decimal value as if they were never typed in by the user in the first place, or you can round off the typed in value, but then there are two ways to do rounding in a macro, so you have to make sure you specify the right one. ...
    (microsoft.public.excel.misc)
  • Re: adCurrency problem in ASP
    ... > What is wrong is your expectation. ... > Non integer values are usually stored in a binary format. ... > decimals, either store it as a integer [in cents, if we are talking ... > currency] or have a good rounding off algoritm. ...
    (microsoft.public.inetserver.asp.general)
  • Re: Need help with rounding on a calculation
    ... a multiple 0f 0.01 and rounding to two decimals. ... Showing your ineptness in following good advice is one thing, ...
    (comp.lang.javascript)