I am doing some decimal multiplication that requires very high accuracy. For some strange reason, my code is a little inaccurate. Why is this happening?
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
long double x=100, y=0.8;
cout<<setprecision(100)<<x*y;
}
Output:
80.00000000000000444089209850062616169452667236328125
As you can see the first few digits are correct but the last few digits are wrong. This code is really simple and I think it has no errors. Can anybody tell me what is wrong?