From 966f9b786ff1749ac9eba9d1e491d18f183f28ba Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Mon, 19 Apr 2021 12:36:25 +0200 Subject: [PATCH] Js Round float before plotting --- app/main/static/js/charges.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/main/static/js/charges.js b/app/main/static/js/charges.js index d0fb228..9df030a 100644 --- a/app/main/static/js/charges.js +++ b/app/main/static/js/charges.js @@ -1,3 +1,7 @@ +function roundToTwo(num) { + return +(Math.round(num + "e+2") + "e-2"); +} + function build_chart(div_selector, data_url, entity_name, category_type) { const main_elt = document.getElementById("main") @@ -247,7 +251,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) { var period_values = Object.values(d).slice(1) var row = {} row['period'] = d.period - row['total'] = d3.sum(period_values) + row['total'] = roundToTwo(d3.sum(period_values)) periods_total_charge.push(row) }); @@ -310,6 +314,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) { } else { categories_total_charge[k] = +d[k] } + categories_total_charge[k] = roundToTwo(categories_total_charge[k]) } ) }) -- libgit2 0.21.2