Use 15 significant digits for float to string conversion
Fixes printing of numbers like 67.65 or 67.35. Closes #1811
This commit is contained in:
parent
bb0133e929
commit
c930807b9f
2 changed files with 12 additions and 4 deletions
|
@ -83,7 +83,7 @@ struct double_policy : boost::spirit::karma::real_policies<T>
|
|||
static unsigned precision(T n) {
|
||||
if ( n == 0.0 ) return 0;
|
||||
using namespace boost::spirit; // for traits
|
||||
return static_cast<unsigned>(15 - boost::math::trunc(log10(traits::get_absolute_value(n))));
|
||||
return static_cast<unsigned>(14 - boost::math::trunc(log10(traits::get_absolute_value(n))));
|
||||
}
|
||||
|
||||
template <typename OutputIterator>
|
||||
|
|
|
@ -82,14 +82,22 @@ int main( int, char*[] )
|
|||
BOOST_TEST_EQ( out, "-1000000000000000" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000000000.1));
|
||||
BOOST_TEST_EQ( out, "100000000000000.1" );
|
||||
to_string(out, double(10000000000000.1));
|
||||
BOOST_TEST_EQ( out, "10000000000000.1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1.00001));
|
||||
BOOST_TEST_EQ( out, "1.00001" );
|
||||
out.clear();
|
||||
|
||||
|
||||
to_string(out, double(67.65));
|
||||
BOOST_TEST_EQ( out, "67.65" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(67.35));
|
||||
BOOST_TEST_EQ( out, "67.35" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1234000000000000));
|
||||
BOOST_TEST_EQ( out, "1234000000000000" );
|
||||
out.clear();
|
||||
|
|
Loading…
Add table
Reference in a new issue