From 01ce0af940bd69c94a2fac8b65219262845cca98 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Feb 2022 18:18:38 +0100 Subject: refactor: clean sewage --- src/utils/general.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/utils/general.cpp') 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 floatToStr(float num, unsigned int width, unsigned int precision) +UniquePtr doubleToStr(double num, unsigned int width, unsigned int precision) { auto str = make_unique(width + precision); - dtostrf(num, width, precision, str->c_str); + + dtostrf(num, static_cast(width), precision, str->c_str); + + return str; +} + +UniquePtr intToStr(int num) +{ + auto width = static_cast(log10(num)); + + auto str = make_unique(width + 1U); + + dtostrf(num, static_cast(width + 1U), 0, str->c_str); + + return str; +} + +UniquePtr uintToStr(unsigned int num) +{ + auto width = static_cast(log10(num)); + + auto str = make_unique(width + 1U); + + dtostrf(num, static_cast(width + 1U), 0, str->c_str); return str; } -- cgit v1.2.3-18-g5258