diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-14 18:18:38 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-02-14 18:18:38 +0100 |
commit | 01ce0af940bd69c94a2fac8b65219262845cca98 (patch) | |
tree | 97c443782ce1cfba90b205183c8aab1e3edb0bb3 /src/utils/general.cpp | |
parent | cb7a167c7dee2fa1a19bd09ede3bae8b140e79da (diff) |
refactor: clean sewage
Diffstat (limited to 'src/utils/general.cpp')
-rw-r--r-- | src/utils/general.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/utils/general.cpp b/src/utils/general.cpp index bbcd4dd..3464c30 100644 --- a/src/utils/general.cpp +++ b/src/utils/general.cpp @@ -5,10 +5,33 @@ void stop() while (true) {} } -unique_ptr<SmartString> floatToStr(float num, unsigned int width, unsigned int precision) +UniquePtr<SmartString> doubleToStr(double num, unsigned int width, unsigned int precision) { auto str = make_unique<SmartString>(width + precision); - dtostrf(num, width, precision, str->c_str); + + dtostrf(num, static_cast<signed char>(width), precision, str->c_str); + + return str; +} + +UniquePtr<SmartString> intToStr(int num) +{ + auto width = static_cast<unsigned int>(log10(num)); + + auto str = make_unique<SmartString>(width + 1U); + + dtostrf(num, static_cast<signed char>(width + 1U), 0, str->c_str); + + return str; +} + +UniquePtr<SmartString> uintToStr(unsigned int num) +{ + auto width = static_cast<unsigned int>(log10(num)); + + auto str = make_unique<SmartString>(width + 1U); + + dtostrf(num, static_cast<signed char>(width + 1U), 0, str->c_str); return str; } |