@cryptotaxi247 / netdata-1 / commits / 2a818270a

automatic selection of Intl.NumberFormat and Number.toLocaleString(); #2103

Costa Tsaousis (ktsaou) committed Apr 19, 2017 at 22:32 UTC 2a818270ae2a1c80f9a750d966ab52545d877986
2 files changed +31 -5
web/dashboard.js
+30 -4
@@ -841,11 +841,37 @@ var NETDATA = window.NETDATA || {};
841 }
842 },
843
844 + testIntlNumberFormat: function() {
845 + var n = 1.12345;
846 + var e1 = "1.12", e2 = "1,12";
847 + var s = "";
848 +
849 + try {
850 + var x = new Intl.NumberFormat(undefined, {
851 + useGrouping: true,
852 + minimumFractionDigits: 2,
853 + maximumFractionDigits: 2
854 + });
855 +
856 + s = x.format(n);
857 + }
858 + catch(e) {
859 + s = "";
860 + }
861 +
862 + console.log(s);
863 + return (s == e1 || s == e2);
864 + },
865 +
866 get: function(min, max) {
845 - //console.log('numberformat');
846 - //this.get = this.getIntlNumberFormat;
847 - console.log('localestring');
848 - this.get = this.getLocaleString;
867 + if(this.testIntlNumberFormat()) {
868 + console.log('numberformat');
869 + this.get = this.getIntlNumberFormat;
870 + }
871 + else {
872 + console.log('localestring');
873 + this.get = this.getLocaleString;
874 + }
875 return this.get(min, max);
876 }
877 };
web/index.html
+1 -1
@@ -3523,4 +3523,4 @@
3523 </div>
3524 </body>
3525 </html>
3526 -<script type="text/javascript" src="dashboard.js?v20170419-2"></script>
3526 +<script type="text/javascript" src="dashboard.js?v20170419-3"></script>