Format the precision and eliminate trailing zeros for 12 digits.
This commit is contained in:
parent
f1337c682a
commit
faa794cf6b
10
MString.cpp
10
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user