Skip to content

Commit 2ba5783

Browse files
committed
Merge branch 'master' of github.com:pantor/inja
2 parents 99b85d6 + 14f0d38 commit 2ba5783

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

include/inja/renderer.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ class Renderer : public NodeVisitor {
437437
const auto args = get_arguments<2>(node);
438438
const int precision = args[1]->get<int>();
439439
const double result = std::round(args[0]->get<double>() * std::pow(10.0, precision)) / std::pow(10.0, precision);
440-
result_ptr = std::make_shared<json>(std::move(result));
440+
if(0==precision){
441+
result_ptr = std::make_shared<json>(int(result));
442+
}else{
443+
result_ptr = std::make_shared<json>(std::move(result));
444+
}
441445
json_tmp_stack.push_back(result_ptr);
442446
json_eval_stack.push(result_ptr.get());
443447
} break;

single_include/inja/inja.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3933,7 +3933,11 @@ class Renderer : public NodeVisitor {
39333933
const auto args = get_arguments<2>(node);
39343934
const int precision = args[1]->get<int>();
39353935
const double result = std::round(args[0]->get<double>() * std::pow(10.0, precision)) / std::pow(10.0, precision);
3936-
result_ptr = std::make_shared<json>(std::move(result));
3936+
if(0==precision){
3937+
result_ptr = std::make_shared<json>(int(result));
3938+
}else{
3939+
result_ptr = std::make_shared<json>(std::move(result));
3940+
}
39373941
json_tmp_stack.push_back(result_ptr);
39383942
json_eval_stack.push(result_ptr.get());
39393943
} break;

test/test-functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ TEST_CASE("functions") {
8888
}
8989

9090
SUBCASE("round") {
91-
CHECK(env.render("{{ round(4, 0) }}", data) == "4.0");
91+
CHECK(env.render("{{ round(4, 0) }}", data) == "4");
9292
CHECK(env.render("{{ round(temperature, 2) }}", data) == "25.68");
9393
// CHECK_THROWS_WITH( env.render("{{ round(name, 2) }}", data), "[inja.exception.json_error]
9494
// [json.exception.type_error.302] type must be number, but is string" );

0 commit comments

Comments
 (0)