[Boost-bugs] [Boost C++ Libraries] #5796: Casting from float to string using "lexical_cast<string>" gives inaccurate values.

Subject: [Boost-bugs] [Boost C++ Libraries] #5796: Casting from float to string using "lexical_cast<string>" gives inaccurate values.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-08-21 09:09:43


#5796: Casting from float to string using "lexical_cast<string>" gives inaccurate
values.
----------------------------------------------------+-----------------------
 Reporter: Mikko Partonen <mikkopartonen@…> | Owner: nasonov
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost 1.47.0 | Severity: Cosmetic
 Keywords: lexical_cast, float |
----------------------------------------------------+-----------------------
 When casting floats to strings with lexical_cast<string>() for use in
 wxTextCtrl, the new boost versions adds a lot of nines or zeroes along
 with some random numbers at the end of the float values.
 For example, with an older boost version, I get "0.96" and "0.8" and with
 new versions, I get "0.959999979" and "0.800000012".

 I believe this new feature has to do with this problem:

 "The previous version of lexical_cast used the default stream precision
 for reading and writing floating-point numbers. For numerics that have a
 corresponding specialization of std::numeric_limits, the current version
 now chooses a precision to match."

 This can easily be fixed by using an older version of lexical_cast.hpp
 file. Wouldn't it be better to fix this issue, so that I wouldn't need to
 use the old version of lexical_cast.hpp?

 I attached the lexical_cast.hpp version with which conversions from floats
 to strings works.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5796>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC