diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-02-25 09:54:50 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2021-06-11 10:53:20 -0400 |
commit | 554c776e08c9ee35fa9e2677e02f4005c11ddbc0 (patch) | |
tree | 1ea2b367e5cd59a8c9b049ceaeb0d6f4253f9aed /core/string | |
parent | 6b0183ec893ddea3f8ae71005b5fce1ae988e8a0 (diff) |
Reformat structure string operators
The order of numbers is not changed except for Transform2D. All logic is done inside of their structures (and not in Variant).
For the number of decimals printed, they now use String::num_real which works best with real_t, except for Color which is fixed at 4 decimals (this is a reliable number of float digits when converting from 16-bpc so it seems like a good choice)
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/ustring.cpp | 6 | ||||
-rw-r--r-- | core/string/ustring.h | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index ec5ec3dd79..83ede0b11b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1594,7 +1594,7 @@ String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) { return s; } -String String::num_real(double p_num) { +String String::num_real(double p_num, bool p_trailing) { if (Math::is_nan(p_num)) { return "nan"; } @@ -1669,8 +1669,10 @@ String String::num_real(double p_num) { dec_int /= 10; } sd = '.' + decimal; - } else { + } else if (p_trailing) { sd = ".0"; + } else { + sd = ""; } if (intn == 0) { diff --git a/core/string/ustring.h b/core/string/ustring.h index f05865165d..82cd3e1667 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -309,7 +309,7 @@ public: String unquote() const; static String num(double p_num, int p_decimals = -1); static String num_scientific(double p_num); - static String num_real(double p_num); + static String num_real(double p_num, bool p_trailing = true); static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false); static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false); static String chr(char32_t p_char); |