0
How to use decimal numbers
I need to use decimals but the code doesn't accept them
6 Answers
+ 2
Attention! Float/Double is not the same. Fix point numbers (like Decimal) can represent every number in their decimal places, floating points (float, double) can't.
Example: 0.2 is not representable with float!
Experimental prove: try to add 1.000 times 0.2 and print out the result.
Manuel Dall'Olio
Standard C++
std::decimal::decimal32, std::decimal::decimal64, and std::decimal::decimal128
Of course you can use others (like BOOST), or write your own datatype.
+ 1
#include <decimal>
using namespace std;
using namespace std::decimal;
int main()
{
decimal32 d = 4.7df;
// your code
}
0
C++
0
Well no, I hadn't even thought about it. I will try that
0
I am a beginner so, please, be patient. How can I incorporate std::decimal::decimal 32 into my code?
0
Aaaah ok thanks