From 01a150adf5cde9da0fc17a63754c7580299e27ae Mon Sep 17 00:00:00 2001 From: Justin Otherguy Date: Sun, 9 Jan 2011 22:00:00 +0100 Subject: [PATCH] better rounding --- htdocs/frontend/javascripts/frontend.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index 5760d2f..09bf440 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -368,11 +368,11 @@ vz.entities.loadData = function() { .attr('title', $.plot.formatDate(new Date(entity.data.max.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); } if (entity.data.average) { - $('#entity-' + entity.uuid + ' .average').text(Math.round(entity.data.average/vz.options.rounding)*vz.options.rounding); - // rounding: Math.round rounds to whole numbers; to round to one decimal (e.g. 15.2) we multiply by 10 (resp. divide through 0.1), round and reverse the multiplication again; therefore "vz.options.rounding" needs to be set to 0.1 in that case + $('#entity-' + entity.uuid + ' .average').text(Math.round(entity.data.average*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); + // rounding: Math.round rounds to whole numbers; to round to one decimal (e.g. 15.2) we multiply by 10, round and reverse the multiplication again; therefore "vz.options.rounding" needs to be set to 1 (for 1 decimal) in that case } if (entity.data.last) { - $('#entity-' + entity.uuid + ' .last').text(Math.round(entity.data.last/vz.options.rounding)*vz.options.rounding); + $('#entity-' + entity.uuid + ' .last').text(Math.round(entity.data.last*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); } }, vz.drawPlot, 'data') );