Commit 966f9b786ff1749ac9eba9d1e491d18f183f28ba

Authored by hitier
1 parent 582e1ee2

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 function build_chart(div_selector, data_url, entity_name, category_type) { 5 function build_chart(div_selector, data_url, entity_name, category_type) {
2 6
3 const main_elt = document.getElementById("main") 7 const main_elt = document.getElementById("main")
@@ -247,7 +251,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) { @@ -247,7 +251,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) {
247 var period_values = Object.values(d).slice(1) 251 var period_values = Object.values(d).slice(1)
248 var row = {} 252 var row = {}
249 row['period'] = d.period 253 row['period'] = d.period
250 - row['total'] = d3.sum(period_values) 254 + row['total'] = roundToTwo(d3.sum(period_values))
251 periods_total_charge.push(row) 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,6 +314,7 @@ function build_chart(div_selector, data_url, entity_name, category_type) {
310 } else { 314 } else {
311 categories_total_charge[k] = +d[k] 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 })