Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CurrencyDecimals Varaible

1 view
Skip to first unread message

riweber

unread,
Jul 30, 2007, 4:58:16 AM7/30/07
to
I need to calculate with values with 9 decimals. So I thought the type
"Currency" is suiteable for my needs. But I read thet this type only
supports 4 decimales. Later I saw in the BCB2007 help that exists a
variable "CurrencyDecimals". The help file says that this is the
variable to set the count of values in a currency value. Does this mean
the type "Currency"? In other words can I set with this variable the
count of decimales in a currency type?

Remy Lebeau (TeamB)

unread,
Jul 30, 2007, 6:37:18 AM7/30/07
to

"riweber" <webe...@atnet.at> wrote in message
news:46ada829$1...@newsgroups.borland.com...

> I need to calculate with values with 9 decimals.

Use floating-point types, such as 'float' or 'double'.

> I thought the type "Currency" is suiteable for my needs.

Nope, not even close. Please read the documentation more carefully:

"Currency is a C++ class that implements the Delphi Currency data type.
Currency inherits a val data member declared as int64 that holds the
currency value. The range of possible currency values is
922337203685477.5808 to 922337203685477.5807. Use Currency to hold monetary
values."

> I read thet this type only supports 4 decimales.

Correct.

> Later I saw in the BCB2007 help that exists a variable
> "CurrencyDecimals". The help file says that this is the variable
> to set the count of values in a currency value. Does this
> mean the type "Currency"?

No. It it only used when using the "m" specifier in one of the Format...()
functions to create a string value that contains a currency amount in it.

> In other words can I set with this variable the count of
> decimales in a currency type?

No.


Gambit


riweber

unread,
Jul 30, 2007, 7:24:08 AM7/30/07
to
Thank you for your answer. The reason why I don't want to use the float
or double types is that want to calculate with 9 decimals fix and not
floating...

Remy Lebeau (TeamB) schrieb:

riweber

unread,
Jul 30, 2007, 7:23:40 AM7/30/07
to Remy Lebeau (TeamB)
Thank you for your answer. The reason why I don't want to use the float
or double types is that want to calculate with 9 decimals fix and not
floating...

Remy Lebeau (TeamB) schrieb:

Eliot Frank

unread,
Jul 30, 2007, 11:04:10 AM7/30/07
to
riweber wrote:
> Thank you for your answer. The reason why I don't want to use the float
> or double types is that want to calculate with 9 decimals fix and not
> floating...
>

You may want to look at an arbitrary/multiple precision library such as GMP.

See http://gmplib.org/

[Disclaimer: I've never used it and don't know if it will work with BCB.]

-Eliot

Frank Peelo

unread,
Jul 31, 2007, 6:18:39 AM7/31/07
to
riweber wrote:
> Thank you for your answer. The reason why I don't want to use the float
> or double types is that want to calculate with 9 decimals fix and not
> floating...

Generally, if you care about the accuracy, you'll want to hold the
values and do the calculations in an integer type and then handle the
decimal point when doing input and output.

This is commonly done when handling currency amounts in situations where
even losing a tenth of a cent could be unacceptable. Float and double
are unsuitable for this. Floating point types are approximations. Early
TurboPascal had a variant which used BCD, but an array of int wrapped in
a class will be more efficient. So it is understandable that you
considered the Currency type. But you may end up writing your own class.

fp

0 new messages