Format the precision and eliminate trailing zeros for 12 digits.

This commit is contained in:
Brad Arant 2024-11-04 09:39:13 -08:00
parent f1337c682a
commit faa794cf6b

View File

@ -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;