diff --git a/src/Core/Scripts/Runtime/Format.js b/src/Core/Scripts/Runtime/Format.js index fddce5620..e177a0ece 100644 --- a/src/Core/Scripts/Runtime/Format.js +++ b/src/Core/Scripts/Runtime/Format.js @@ -8,7 +8,7 @@ function _commaFormatNumber(number, groups, decimal, comma) { number = number.substr(0, decimalIndex); } - var negative = number.startsWith('-'); + var negative = ss.startsWith(number, '-'); if (negative) { number = number.substr(1); } @@ -16,6 +16,9 @@ function _commaFormatNumber(number, groups, decimal, comma) { var groupIndex = 0; var groupSize = groups[groupIndex]; if (number.length < groupSize) { + if (negative) { + number = '-' + number; + } return decimalPart ? number + decimalPart : number; } @@ -72,7 +75,7 @@ _formatters['Number'] = function(number, format, culture) { if (precision != -1) { s = padLeft(s, precision, '0'); } - if (number < 0) { + if (number < 0 && s != 0) { s = '-' + s; } break; @@ -92,6 +95,10 @@ _formatters['Number'] = function(number, format, culture) { else { s = number.toExponential(precision); } + if (nf.ds != '.') { + var index = s.indexOf('.'); + s = s.substr(0, index) + nf.ds + s.substr(index + 1); + } if (fs == 'E') { s = s.toUpperCase(); } @@ -101,7 +108,7 @@ _formatters['Number'] = function(number, format, culture) { if (precision == -1) { precision = nf.dd; } - s = number.toFixed(precision).toString(); + s = (+(Math.round(+(number + 'e' + precision)) + 'e' + -precision)).toFixed(precision); if (precision && (nf.ds != '.')) { var index = s.indexOf('.'); s = s.substr(0, index) + nf.ds + s.substr(index + 1); @@ -121,10 +128,10 @@ _formatters['Number'] = function(number, format, culture) { } s = _commaFormatNumber(s, nf.curGW, nf.curDS, nf.curGS); if (number < 0) { - s = String.format(culture, nf.curNP, s); + s = ss.format(culture, nf.curNP, s); } else { - s = String.format(culture, nf.curPP, s); + s = ss.format(culture, nf.curPP, s); } break; case 'p': case 'P': @@ -138,10 +145,10 @@ _formatters['Number'] = function(number, format, culture) { } s = _commaFormatNumber(s, nf.perGW, nf.perDS, nf.perGS); if (number < 0) { - s = String.format(culture, nf.perNP, s); + s = ss.format(culture, nf.perNP, s); } else { - s = String.format(culture, nf.perPP, s); + s = ss.format(culture, nf.perPP, s); } break; } diff --git a/src/Core/Scripts/Runtime/Misc.js b/src/Core/Scripts/Runtime/Misc.js index 9275e4d8b..da6855f5a 100644 --- a/src/Core/Scripts/Runtime/Misc.js +++ b/src/Core/Scripts/Runtime/Misc.js @@ -47,6 +47,12 @@ function parseNumber(s) { if (!s || !s.length) { return 0; } + + if (ss.culture.current.nf.gs.length) + s = s.replace(new RegExp('\\' + ss.culture.current.nf.gs, 'g'), ''); + if (ss.culture.current.nf.ds.length) + s = s.replace(new RegExp('\\' + ss.culture.current.nf.ds), '.'); + if ((s.indexOf('.') >= 0) || (s.indexOf('e') >= 0) || endsWith(s, 'f') || endsWith(s, 'F')) { return parseFloat(s);