Subject | Re: [ib-support] Really strange calculating behaviour of IB |
---|---|
Author | David K. Trudgett |
Post date | 2002-02-14T01:35:59Z |
On Friday 2002-02-15 at 01:58:33 +0100, guido.klapperich@... wrote:
scaling yourself using your external application or UDFs. So, you
could store $123.45 as 1234500, for instance. In your application, you
simply need to move the decimal point four places to the left (divide
by 10000) to display the value in dollar (or whatever) units. You only
need to use NUMERIC(18,0) in the database, in that case. When doing
calculations, you need to observe the rules of scale; for example,
(a) $12.54 x 13.6 = $170.544
i.e.,
(b) 125400 x 136000 = 17054400000 ($170,540 -- wrong!)
Adjusting the scale by four digits gives the correct answer of
1705440, which is $170.544.
When multiplying, add the scales of the multiplicands (2 and 1, in the
case of example "a", 4 and 4 in the case of example "b").
David Trudgett
> > For the moment I am just glad that I have not used scaled numerics inThe values the database stores don't have to be scaled. You can do the
> > my apps - I just spend lots of time writing triggers etc to perform
> > explicit rounding. It may not be perfect, but so far it has been
> > consistent.
> >
>
> And how do you store money-values ?
scaling yourself using your external application or UDFs. So, you
could store $123.45 as 1234500, for instance. In your application, you
simply need to move the decimal point four places to the left (divide
by 10000) to display the value in dollar (or whatever) units. You only
need to use NUMERIC(18,0) in the database, in that case. When doing
calculations, you need to observe the rules of scale; for example,
(a) $12.54 x 13.6 = $170.544
i.e.,
(b) 125400 x 136000 = 17054400000 ($170,540 -- wrong!)
Adjusting the scale by four digits gives the correct answer of
1705440, which is $170.544.
When multiplying, add the scales of the multiplicands (2 and 1, in the
case of example "a", 4 and 4 in the case of example "b").
David Trudgett