Boost logo

Boost :

From: Jonathan Franklin (franklin.jonathan_at_[hidden])
Date: 2007-06-01 15:57:55


On 6/1/07, Alexander Nasonov <alnsn_at_[hidden]> wrote:
>
> Jonathan Franklin wrote:
> > FWIW, sending the double value to std::cout works as expected:
> > double d = 72.35;
> > std::string s = boost::lexical_cast<std::string>(d);
> > printf("%s\n", s.c_str()); // prints 72.34999999999999
> > std::cout << d << std::endl; // prints 72.35
>
> because default precision is 6. Try to set it to
> numeric_limits<double>::digits10 + 1.

Oops, good call.

  std::cout.precision(std::numeric_limits<double>::digits10 + 1);
  std::cout << d << std::endl; // prints 72.34999999999999

Jon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk