From 95472c17147ab4aab24a7c3c4644aafeeed99ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Thu, 26 Sep 2019 15:08:30 +0200 Subject: [PATCH] Delete NaN text in table and toString and replace fixed by Precision in toString --- content/onedataset.html | 3 ++- static/scripts/data.js | 2 +- static/scripts/noNan.js | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 static/scripts/noNan.js diff --git a/content/onedataset.html b/content/onedataset.html index 38444070..96009f95 100644 --- a/content/onedataset.html +++ b/content/onedataset.html @@ -8,6 +8,7 @@ draft: false + @@ -128,7 +129,7 @@ draft: false var rowd=[] rowd.push(String.raw`${LatexInline[0]} ${el.initial.toLaTeX()} \rightarrow ${el.final.toLaTeX()}${LatexInline[1]}`) var e=[el.Eabs,el.Efluo,el.EZPE,el.Eadia,el.Ezz] - e.forEach((val)=>rowd.push(val.toFixed(2))) + e.forEach((val)=>rowd.push(noNanPrecision(val,3))) rowd.forEach((d)=>{ td=document.createElement("td") td.innerText=d diff --git a/static/scripts/data.js b/static/scripts/data.js index 0db9b000..3e5f34ed 100644 --- a/static/scripts/data.js +++ b/static/scripts/data.js @@ -96,7 +96,7 @@ class excitation extends excitationBase{ return this.Eadia-this.EZPE } toString() { - return this.start+ ', ' + this.end +', '+ this.Eabs.toPrecision(3); + return this.start+ ', ' + this.end +', '+ noNanPrecision(this.Eabs,3); } } diff --git a/static/scripts/noNan.js b/static/scripts/noNan.js new file mode 100644 index 00000000..46edcefd --- /dev/null +++ b/static/scripts/noNan.js @@ -0,0 +1,19 @@ +function noNanPrecision(number,precision) +{ + if(Number.isNaN(number)){ + return "" + } + else { + return number.toPrecision(precision) + } +} + +function noNanFixed(number,precision) +{ + if(Number.isNaN(number)){ + return "" + } + else { + return number.toFixed(precision) + } +} \ No newline at end of file