diff options
Diffstat (limited to 'src/std/conversion.cpp')
-rw-r--r-- | src/std/conversion.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
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<SmartString> doubleToStr(double num, unsigned int width, unsigned int precision) +{ + auto str = make_unique<SmartString>(width + precision); + + 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; +} |