Skip to content

Commit

Permalink
Fixed #9399 - InputNumber: issues with decimal separator for some loc…
Browse files Browse the repository at this point in the history
…ales, 0s are added to input
  • Loading branch information
mertsincan committed Sep 8, 2021
1 parent e8d4c10 commit 7819d16
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ export class InputNumber implements OnInit,ControlValueAccessor {
const numerals = [...new Intl.NumberFormat(this.locale, {useGrouping: false}).format(9876543210)].reverse();
const index = new Map(numerals.map((d, i) => [d, i]));
this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
this._decimal = this.getDecimalExpression();
this._group = this.getGroupingExpression();
this._minusSign = this.getMinusSignExpression();
this._currency = this.getCurrencyExpression();
this._decimal = this.getDecimalExpression();
this._suffix = this.getSuffixExpression();
this._prefix = this.getPrefixExpression();
this._index = d => index.get(d);
Expand All @@ -237,8 +237,8 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

getDecimalExpression() {
const formatter = new Intl.NumberFormat(this.locale, {useGrouping: false});
return new RegExp(`[${formatter.format(1.1).trim().replace(this._numeral, '')}]`, 'g');
const formatter = new Intl.NumberFormat(this.locale, {...this.getOptions(), useGrouping: false});
return new RegExp(`[${formatter.format(1.1).replace(this._currency, '').trim().replace(this._numeral, '')}]`, 'g');
}

getGroupingExpression() {
Expand All @@ -254,8 +254,9 @@ export class InputNumber implements OnInit,ControlValueAccessor {

getCurrencyExpression() {
if (this.currency) {
const formatter = new Intl.NumberFormat(this.locale, {style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay});
return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._decimal, '').replace(this._group, '')}]`, 'g');
const formatter = new Intl.NumberFormat(this.locale, {style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay,
minimumFractionDigits: 0, maximumFractionDigits: 0});
return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._group, '')}]`, 'g');
}

return new RegExp(`[]`,'g');
Expand Down

0 comments on commit 7819d16

Please sign in to comment.