In C#, there is a type called decimal
(the System.Decimal structure). I have found information that shows how it is better than float
and double
types for some cases:
Is there any similar type for Borland C++ Builder programs?
The decimal
type in C#, .NET's System.Decimal
type, is just a floating point number stored as base-10 instead of base-2 encoding. float
and double
are more typical base-2 floating point numbers. That is, a double
is stored as +/- x * 2^y
while a decimal is stored as +/- x * 10 ^ y
. That's why it does better for, as one example, financial data, which is typically expressed in terms of x * 10^-2
. The IEEE standard 754 (the floating point math standard) calls this "decimal floating point" math, and defines a 32- and 64-bit version of each.
In C++, these types are implemented in the std::decimal
namespace, and are called std::decimal::decimal32
and std::decimal::decimal64
, in the <decimal>
header. If Borland C++ builder has such a type, you will find it there. GNU's C++ library includes this header but, AFAIK it's not actually part of the standard yet, so BCB may not have it. If that's the case, you'll need to use a third-party library. @dash's example of Intel's Decimal Floating Point library is probably the best known such library, though a Google search for IEEE 754 Decimal
should turn up others if, for some reason, you need them.
These are the float types that you can use in Delphi:
single : 4 bytes (32bits)
real : 6 bytes (48bits)
double : 8 bytes (64bits)
currency: 8 bytes (64bits) (this is probably what you're looking for)
extended: 10 bytes (80bits) (maps to double when you compile to x64!)
In C++ builder there seems to be a System::Currency
class that mimics Delphi's built in currency type. Maybe it helps to look into that.
I found this link Borland C++ Primitive Data types . View it in HTML.
There is a long double type having capacity of 10 bytes.
The document is informative. You may want to read it anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With