Skip to content

Commit

Permalink
Removal of trailing zeros on decimals.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 19, 2024
1 parent 1940205 commit ec94d83
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/core/DynamicObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,19 @@ void DynamicObject::setArrayElement(size_t index, std::unique_ptr<DynamicObject>
std::string DynamicObject::toString() {
if(this->isNil())
return "nil";
else if(this->isNumber())
return std::to_string(this->getNumber());
else if(this->isNumber()) {
std::string numstr = std::to_string(this->getNumber());
size_t dotPos = numstr.find('.');

if(dotPos != std::string::npos) {
numstr.erase(numstr.find_last_not_of('0') + 1);

if(numstr.back() == '.')
numstr.pop_back();
}

return numstr;
}
else if(this->isString())
return this->getString();
else if(this->isBool())
Expand Down

0 comments on commit ec94d83

Please sign in to comment.