From 2304c43a607ef81e0b1a2acb4f158a649a54dd17 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 29 Apr 2020 16:21:45 +0200 Subject: [PATCH] fixed ingredient calculator rounding error --- cookbook/templates/recipe_view.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 6467244ec..aa353d01d 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -377,6 +377,10 @@ trigger: 'focus' }); + function roundToTwo(num) { + return +(Math.round(num + "e+2") + "e-2"); + } + function reloadIngredients() { factor = Number($('#in_factor').val()); ingredients = { @@ -386,7 +390,7 @@ } for (var key in ingredients) { - $('#ing_' + key).html(Math.round(ingredients[key] * factor)) + $('#ing_' + key).html(roundToTwo(ingredients[key] * factor)) } }