diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-10-17 15:52:11 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-10-23 12:23:40 +0200 |
commit | 43687b4781cdcd7c4e299dc625263bc3982a529f (patch) | |
tree | acf8fe6ee82aee548402af7d8b8b6074c30f7fa1 /src | |
parent | decbde16165cf3e4455edd0c5caeac991d0c01e6 (diff) | |
download | qtlocation-mapboxgl-43687b4781cdcd7c4e299dc625263bc3982a529f.tar.gz |
[core] add ability to stringify doubles that are integer with and without trailing ".0"
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/util/dtoa.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/util/dtoa.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/string.cpp | 13 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/mbgl/util/dtoa.cpp b/src/mbgl/util/dtoa.cpp index fce1f122b7..934a78f7ab 100644 --- a/src/mbgl/util/dtoa.cpp +++ b/src/mbgl/util/dtoa.cpp @@ -13,12 +13,12 @@ namespace util { #if !defined(_WINDOWS) -std::string dtoa(double value) { +std::string dtoa(double value, bool decimal) { std::string data; data.resize(25); auto end = rapidjson::internal::dtoa(value, const_cast<char*>(data.data())); auto length = end - data.data(); - if (length >= 3 && end[-1] == '0' && end[-2] == '.') { + if (!decimal && length >= 3 && end[-1] == '0' && end[-2] == '.') { // Remove trailing ".0" for integers length -= 2; } diff --git a/src/mbgl/util/dtoa.hpp b/src/mbgl/util/dtoa.hpp index e6b1659aa2..22aa925675 100644 --- a/src/mbgl/util/dtoa.hpp +++ b/src/mbgl/util/dtoa.hpp @@ -6,7 +6,7 @@ namespace mbgl { namespace util { -std::string dtoa(double value); +std::string dtoa(double value, bool decimal = false); inline double stod(const std::string& str) { return ::strtod(str.c_str(), nullptr); diff --git a/src/mbgl/util/string.cpp b/src/mbgl/util/string.cpp index 4738209382..b20b3fb7ed 100644 --- a/src/mbgl/util/string.cpp +++ b/src/mbgl/util/string.cpp @@ -4,16 +4,17 @@ namespace mbgl { namespace util { -std::string toString(float num) { - return dtoa(num); +std::string toString(float num, bool decimal) { + return dtoa(num, decimal); } -std::string toString(double num) { - return dtoa(num); +std::string toString(double num, bool decimal) { + return dtoa(num, decimal); } -std::string toString(long double num) { - return dtoa(num); +std::string toString(long double num, bool decimal) { + return dtoa(num, decimal); +} } } // namespace util |