|
Boost Users : |
Subject: Re: [Boost-users] [lexical_cast] float-to-string rounding error (notfound with cout)
From: Grant Birchmeier (gbirchmeier_at_[hidden])
Date: 2009-04-30 13:49:54
On Thu, Apr 30, 2009 at 12:20 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>> (1) Is there a way to eliminate this trailing '1' with lexical_cast
>> (presumably some wierd rounding error)?
>
> Try this code:
>
> std::cout << f2 << std::endl;
> std::cout << boost::lexical_cast<std::string>(f2) << std::endl;
>
> std::cout << f - f2 << std::endl;
>
> which will hopefully answer your question.
The resulting output from your code, Peter, is:
123.123
123.123001
123.123
123.123001
0
That's just great. So internally (on my system, anyway) the two
floats are equal, and the two methods of converting it to string just
round it differently. Curses.
Thanks for the help
-Grant
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net