Commit 966f9b786ff1749ac9eba9d1e491d18f183f28ba
1 parent
582e1ee2
Exists in
master
and in
4 other branches
Js Round float before plotting
Showing
1 changed file
with
6 additions
and
1 deletions
Show diff stats
app/main/static/js/charges.js
1 | +function roundToTwo(num) { | |
2 | + return +(Math.round(num + "e+2") + "e-2"); | |
3 | +} | |
4 | + | |
1 | 5 | function build_chart(div_selector, data_url, entity_name, category_type) { |
2 | 6 | |
3 | 7 | const main_elt = document.getElementById("main") |
... | ... | @@ -247,7 +251,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) { |
247 | 251 | var period_values = Object.values(d).slice(1) |
248 | 252 | var row = {} |
249 | 253 | row['period'] = d.period |
250 | - row['total'] = d3.sum(period_values) | |
254 | + row['total'] = roundToTwo(d3.sum(period_values)) | |
251 | 255 | periods_total_charge.push(row) |
252 | 256 | }); |
253 | 257 | |
... | ... | @@ -310,6 +314,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) { |
310 | 314 | } else { |
311 | 315 | categories_total_charge[k] = +d[k] |
312 | 316 | } |
317 | + categories_total_charge[k] = roundToTwo(categories_total_charge[k]) | |
313 | 318 | } |
314 | 319 | ) |
315 | 320 | }) | ... | ... |