Skip to content

Commit

Permalink
Input in negative number with required float part should not revert s…
Browse files Browse the repository at this point in the history
…ign (#3165)
  • Loading branch information
mrjohn0011 authored Mar 2, 2018
1 parent d92741b commit 7281275
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/localization/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ var numberLocalization = dependencyInjector({
return 1;
}

var negativeEtalon = this.format(-1, format),
separators = this._getSeparators(),
var separators = this._getSeparators(),
regExp = new RegExp("[0-9" + escapeRegExp(separators.decimalSeparator + separators.thousandsSeparator) + "]+", "g"),
negativeEtalon = this.format(-1, format).replace(regExp, "1"),
cleanedText = text.replace(regExp, "1");

return cleanedText === negativeEtalon ? -1 : 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ QUnit.test("parse: test starts with not digit symbols", function(assert) {
assert.equal(numberLocalization.parse("1.2 руб."), 1.2);
});

QUnit.test("parse: test different negative format", function(assert) {
assert.equal(numberLocalization.parse("<<1.0>>", "#0.00;<<#0.00>>"), -1);
});

QUnit.test('Fixed point numeric formats', function(assert) {
assert.equal(numberLocalization.format(23.04059872, { type: "fIxedPoint", precision: 4 }), '23.0406');
assert.equal(numberLocalization.format(23.04059872, "fIxedPoint"), "23");
Expand Down Expand Up @@ -870,7 +874,7 @@ QUnit.test("date", function(assert) {

QUnit.test("'no parser' errors", function(assert) {
var numberFormatter = function(value) {
return 1;
return "1";
},
dateFormatter = function(value) {
return new Date(0, 0, 1);
Expand Down

0 comments on commit 7281275

Please sign in to comment.