From c60ac64e8fa16ffc092c6c773ebe49a1312045cd Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 15 Oct 2022 17:36:22 -0500 Subject: Fix big negative numbers printing incorrect decimals in num_real --- core/string/ustring.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'core') 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); } -- cgit v1.2.3