I have a double with long decimal values eg : double x =32.1347896
I wanted to round it to 32.140000000
I tried using ceil (x*100)/100 but it returns 32.1399999
Please help
Floating point values are not good at storing exact values. You easily get rounding errors like this. You should consider storing the value without rounding it, and instead limit the number of decimals when you output the value.
1 2 3 4 5 6 7 8
#include <iostream>
#include <iomanip>
int main()
{
double x = 32.1347896;
std::cout << std::fixed << std::setprecision(2) << x; // Prints "32.13"
}