Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix float data conversion to string

Fixes precision digits, closing #430
Also avoids forcing a trailing '.0', closing #1627
  • Loading branch information...
commit 19522ac509a518f0f01ec3e53dfdeeacb5699d4e 1 parent 3d7575c
@strk strk authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 include/mapnik/util/conversions.hpp
View
8 include/mapnik/util/conversions.hpp
@@ -68,7 +68,11 @@ struct double_policy : boost::spirit::karma::real_policies<T>
{
typedef boost::spirit::karma::real_policies<T> base_type;
static int floatfield(T n) { return base_type::fmtflags::fixed; }
- static unsigned precision(T n) { return 16 ;}
+ static unsigned precision(T n) { return 15 - trunc(log10(n)); }
+ template <typename OutputIterator>
+ static bool dot(OutputIterator& sink, T n, unsigned precision) {
+ return n ? *sink = '.', true : false;
+ }
};
@@ -77,7 +81,7 @@ template <>
inline bool to_string(std::string & str, double value)
{
namespace karma = boost::spirit::karma;
- typedef boost::spirit::karma::real_generator<double, double_policy<double> > double_type;
+ typedef karma::real_generator<double, double_policy<double> > double_type;
std::back_insert_iterator<std::string> sink(str);
return karma::generate(sink, double_type(), value);
}
Please sign in to comment.
Something went wrong with that request. Please try again.