Format the precision and eliminate trailing zeros for 12 digits.
This commit is contained in:
1 parent
f1337c682a
commit
faa794cf6b
1 file changed
+8
-2
+8
-2
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user