I tried this:
#include <cstdlib>
#include <iostream>
int main ()
{
char *p;
long double l = strtold("12312.12345", &p);
std::cout << l << std::endl; //prints 12312.1
}
How to avoid that kind of rounding?
I tried this:
#include <cstdlib>
#include <iostream>
int main ()
{
char *p;
long double l = strtold("12312.12345", &p);
std::cout << l << std::endl; //prints 12312.1
}
How to avoid that kind of rounding?
Your string is correctly parsed. You can verify it in this way:
// Remove the integer part ...
std::cout << (l - 12312) << std::endl;
// ... and you get the fractional part correctly displayed:
// 0.12345
So the reported problem is just a matter of output formatting.