From faa794cf6bfdd77a9cbfe8e0f1c131c95b5bbabe Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 4 Nov 2024 09:39:13 -0800 Subject: [PATCH] Format the precision and eliminate trailing zeros for 12 digits. --- MString.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/MString.cpp b/MString.cpp index e7e8dde..28f9ce1 100644 --- a/MString.cpp +++ b/MString.cpp @@ -86,7 +86,10 @@ namespace coreutils { } MString::MString(double value) { - std::string temp = std::format("{}", value); + std::string temp = std::format("{:.12f}", value); + temp.erase(temp.find_last_not_of('0') + 1, std::string::npos); + if (temp.back() == '.') + temp.pop_back(); setSize(temp.length()); memcpy(this->data, (char *)temp.data(), temp.length()); cursor = this->data; @@ -133,7 +136,10 @@ namespace coreutils { } MString &MString::operator=(double value) { - std::string temp = std::format("{}", value); + std::string temp = std::format("{:.12f}", value); + temp.erase(temp.find_last_not_of('0') + 1, std::string::npos); + if (temp.back() == '.') + temp.pop_back(); setSize(temp.length()); memcpy(this->data, (char *)temp.data(), temp.length()); cursor = this->data;