Is there any "type" in Borland C ++ Builder as a "decimal" from C #?

In C #, there is a type called decimal (a System.Decimal structure). I found information that shows how this is better than the float and double types for some cases:

Is there a similar type for Borland C ++ Builder programs?

+6
source share
3 answers

The decimal type of type C #, .NET System.Decimal is just a floating point number that is stored as base-10 instead of base-2 encoding. float and double are more typical base-2 floating-point numbers. That is, double is stored as +/- x * 2^y , while the decimal value is stored as +/- x * 10 ^ y . That is why it is better suited, for example, to financial data, which are usually expressed in terms of x * 10^-2 . The IEEE 754 standard (mathematical standard for floating point) calls this math with "decimal floating point" and defines a 32- and 64-bit version of each of them.

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 this type, you will find it there. The GNU C ++ library includes this header, but AFAIK is not yet part of the standard, so BCB may not have it. In this case, you will need to use a third-party library. Intel @dash example The decimal floating point library is probably the best known library of this kind, although a Google search for IEEE 754 Decimal should appear different if for some reason you need them.

+8
source

These are the types of float 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!) 

The C ++ builder seems to have a System::Currency class that mimics Delphi built into a currency type. Maybe this helps to understand this.

+3
source

I found this link Borland C ++ Primitive Data types . View it in HTML.

There is a long double type having a capacity of 10 bytes.

The document is informative. You might want to read it.

+2
source

Source: https://habr.com/ru/post/918521/


All Articles