From bcdce9633dc351d3bc7f347a165348b8fab87cd9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Feb 2022 12:33:52 +0100 Subject: refactor: reorganize files & improve classes --- src/std/conversion.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/std/conversion.cpp (limited to 'src/std/conversion.cpp') diff --git a/src/std/conversion.cpp b/src/std/conversion.cpp new file mode 100644 index 0000000..a2a624d --- /dev/null +++ b/src/std/conversion.cpp @@ -0,0 +1,32 @@ +#include "conversion.hpp" + +UniquePtr doubleToStr(double num, unsigned int width, unsigned int precision) +{ + auto str = make_unique(width + precision); + + 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