diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-04-19 22:32:01 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-04-19 22:32:01 +0300 |
commit | 2a818270ae2a1c80f9a750d966ab52545d877986 (patch) | |
tree | cf94890de8a8277009a88aef31163148e0e1fc4b /web | |
parent | 8889e7941124803cafb87318a23be99dfd82a29c (diff) |
automatic selection of Intl.NumberFormat and Number.toLocaleString(); #2103
Diffstat (limited to 'web')
-rw-r--r-- | web/dashboard.js | 34 | ||||
-rw-r--r-- | web/index.html | 2 |
2 files changed, 31 insertions, 5 deletions
diff --git a/web/dashboard.js b/web/dashboard.js index def7691475..1073efcdb5 100644 --- a/web/dashboard.js +++ b/web/dashboard.js @@ -841,11 +841,37 @@ var NETDATA = window.NETDATA || {}; } }, + testIntlNumberFormat: function() { + var n = 1.12345; + var e1 = "1.12", e2 = "1,12"; + var s = ""; + + try { + var x = new Intl.NumberFormat(undefined, { + useGrouping: true, + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }); + + s = x.format(n); + } + catch(e) { + s = ""; + } + + console.log(s); + return (s == e1 || s == e2); + }, + get: function(min, max) { - //console.log('numberformat'); - //this.get = this.getIntlNumberFormat; - console.log('localestring'); - this.get = this.getLocaleString; + if(this.testIntlNumberFormat()) { + console.log('numberformat'); + this.get = this.getIntlNumberFormat; + } + else { + console.log('localestring'); + this.get = this.getLocaleString; + } return this.get(min, max); } }; diff --git a/web/index.html b/web/index.html index 21c03f7f05..ad6a646c5a 100644 --- a/web/index.html +++ b/web/index.html @@ -3523,4 +3523,4 @@ </div> </body> </html> -<script type="text/javascript" src="dashboard.js?v20170419-2"></script> +<script type="text/javascript" src="dashboard.js?v20170419-3"></script> |