Subject | RE: [ib-support] what is the best type for storing currency field s? |
---|---|
Author | Wilson, Fred |
Post date | 2002-02-13T19:05:57Z |
Something that we've done for all currency and weight columns, is define
them as Integer. This way, it's up to the client applications, through a
rules class, to know what the units themselves are. The database doesn't
care. For instance, for applications here in the US, the currency is $ 0.001
(tenths of a cent) for postage and 0.1 (tens of a ounce) for mailpiece
weights. Sites in other countries use different units (grams instead of
ounces, for instance), but the database doesn't know, nor care. Data for the
rules class is stored in the database. We never have rounding problems,
etc., with this approach.
Best regards,
Fred Wilson
SE, Bell & Howell
fred.wilson@... <mailto:fred.wilson@...>
-----Original Message-----
From: David K. Trudgett [mailto:dkt@...]
Sent: Tuesday, February 12, 2002 4:06 PM
To: ib-support@yahoogroups.com
Subject: Re: [ib-support] what is the best type for storing currency fields?
them as Integer. This way, it's up to the client applications, through a
rules class, to know what the units themselves are. The database doesn't
care. For instance, for applications here in the US, the currency is $ 0.001
(tenths of a cent) for postage and 0.1 (tens of a ounce) for mailpiece
weights. Sites in other countries use different units (grams instead of
ounces, for instance), but the database doesn't know, nor care. Data for the
rules class is stored in the database. We never have rounding problems,
etc., with this approach.
Best regards,
Fred Wilson
SE, Bell & Howell
fred.wilson@... <mailto:fred.wilson@...>
-----Original Message-----
From: David K. Trudgett [mailto:dkt@...]
Sent: Tuesday, February 12, 2002 4:06 PM
To: ib-support@yahoogroups.com
Subject: Re: [ib-support] what is the best type for storing currency fields?
On Tuesday 2002-02-12 at 09:54:28 -0300, Marcelo Miorelli wrote:
> Hello folks,
> I know this question might have been raised here a couple of times, still
I
> dont remember, and as long as I work with Interbase, since 1997, I am
using
> the double precision. Now I saw some messages telling about numeric(15,2),
> so can someone tell me if I might be right, or it would be better to use
> this numeric field intead.
If you use DOUBLE PRECISION for currency values you have to be very
cautious about rounding and precision. If you try to store a value
that has more significant places than a DOUBLE supports, your value
will be rounded to the maximum number of significant digits (since you
have been using DOUBLE PRECISION for currency, you should know what
that is better than I ;-) -- should be around 15 decimal digits).
Furthermore, certain mathematical and arithmetical operations may
produce inexact results. This is not usually acceptable in currency
values.
If you use INT64 (NUMERIC(18,0) for instance), you don't have to worry
about those problems, except that one obviously can't store a value
that contains 19 decimal digits or more! One problem with INT64,
though, is that not all client-side software can handle it properly.
You just need to do some testing to make sure that isn't a problem for
you.
David Trudgett
Yahoo! Groups Sponsor
ADVERTISEMENT
<http://rd.yahoo.com/M=218512.1856015.3360178.1269402/D=egroupweb/S=17050077
09:HM/A=928901/R=0/*http://ad.doubleclick.net/clk;3788034;6800959;v%3fhttp:/
/www.verisign.com/cgi-bin/go.cgi?a=b228473240057000>
<http://us.adserver.yahoo.com/l?M=218512.1856015.3360178.1269402/D=egroupmai
l/S=1705007709:HM/A=928901/rand=937630607>
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .