-3

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
}

demo

How to avoid that kind of rounding?

St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • It´s not `strtold`s fault. See http://stackoverflow.com/questions/3923202/set-the-digits-after-decimal-point – deviantfan Jun 21 '15 at 20:13

1 Answers1

1

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.

dlask
  • 8,776
  • 1
  • 26
  • 30