diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2022-10-15 17:36:22 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2022-10-15 17:57:54 -0500 |
commit | c60ac64e8fa16ffc092c6c773ebe49a1312045cd (patch) | |
tree | e1c14f111394c62ea2b24a437fa1a8528f039079 /core | |
parent | dc4b6165962536b53c4c1471fcf0be43c70e2335 (diff) |
Fix big negative numbers printing incorrect decimals in num_real
Diffstat (limited to 'core')
-rw-r--r-- | core/string/ustring.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 671b06f0ed..2e0ad94fcf 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1567,10 +1567,11 @@ String String::num_real(double p_num, bool p_trailing) { #else int decimals = 6; #endif - // We want to align the digits to the above sane default, so we only - // need to subtract log10 for numbers with a positive power of ten. - if (p_num > 10) { - decimals -= (int)floor(log10(p_num)); + // We want to align the digits to the above sane default, so we only need + // to subtract log10 for numbers with a positive power of ten magnitude. + double abs_num = Math::abs(p_num); + if (abs_num > 10) { + decimals -= (int)floor(log10(abs_num)); } return num(p_num, decimals); } |