mirror of
https://github.com/pantor/inja.git
synced 2026-09-15 10:28:02 +00:00
Fixed an issue with round (#207)
* Fix the problem that the result has a decimal point when the round function, when the precision is 0. * fix tests/test-functions.cpp:91 for round check
This commit is contained in:
@@ -439,7 +439,11 @@ class Renderer : public NodeVisitor {
|
||||
const auto args = get_arguments<2>(node);
|
||||
const int precision = args[1]->get<int>();
|
||||
const double result = std::round(args[0]->get<double>() * std::pow(10.0, precision)) / std::pow(10.0, precision);
|
||||
result_ptr = std::make_shared<json>(std::move(result));
|
||||
if(0==precision){
|
||||
result_ptr = std::make_shared<json>(int(result));
|
||||
}else{
|
||||
result_ptr = std::make_shared<json>(std::move(result));
|
||||
}
|
||||
json_tmp_stack.push_back(result_ptr);
|
||||
json_eval_stack.push(result_ptr.get());
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user