From 2cdd58acaec0c79c2ee3497aa01f92d001382164 Mon Sep 17 00:00:00 2001 From: yamanq Date: Mon, 16 Apr 2018 00:49:30 -0400 Subject: [PATCH] rounding --- SmearcarDB/static/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SmearcarDB/static/index.js b/SmearcarDB/static/index.js index cafbf5e..918e501 100644 --- a/SmearcarDB/static/index.js +++ b/SmearcarDB/static/index.js @@ -48,6 +48,18 @@ var dropOpStore = {}; // } // } +// This Function is property of https://stackoverflow.com/questions/10015027/javascript-tofixed-not-rounding/32605063#32605063 +function roundTo(n, digits) { + if (digits === undefined) { + digits = 0; + } + + var multiplicator = Math.pow(10, digits); + n = parseFloat((n * multiplicator).toFixed(11)); + return Math.round(n) / multiplicator; +} + + function createNav() { for (var i = 0; i < navi.length; i++) { // Create navigation tabs. var side = document.getElementById("sidebar"); @@ -211,7 +223,7 @@ function generateDropOp() { // For options that change based on data. dataBox.children[tableNum].appendChild(pT2); } p1.appendChild(document.createTextNode(phonemes[i])); - p2.appendChild(document.createTextNode(langInfo.phonemes[phonemes[i]])); + p2.appendChild(document.createTextNode(roundTo(langInfo.phonemes[phonemes[i]], 2))); dataBox.children[tableNum].appendChild(p1); dataBox.children[tableNum].appendChild(p2); }