diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-17 17:31:47 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-17 17:31:47 +0200 |
commit | fde8838316f3f73e91ddc4e203a9a2a6c0ac327b (patch) | |
tree | cfa05453dd13f308222de4b017bbe8ef8566b32e /core | |
parent | 69bcda3dd2d9c181c0f5d72a57b49eed4a10f54c (diff) | |
parent | c60ac64e8fa16ffc092c6c773ebe49a1312045cd (diff) |
Merge pull request #67463 from aaronfranke/num-real-negative
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); } |