diff --git a/src/numberFormat.ts b/src/numberFormat.ts index 3cf9d8a..e1d3b2b 100644 --- a/src/numberFormat.ts +++ b/src/numberFormat.ts @@ -23,7 +23,7 @@ export class NumberFormat { constructor(options: NumberInputOptions) { const { formatStyle: style, currency, unit, locale, precision } = options const numberFormat = new Intl.NumberFormat(locale, { currency, unit, style, minimumFractionDigits: style !== NumberFormatStyle.Currency ? 1 : undefined }) - const ps = numberFormat.format(123456) + const ps = numberFormat.format(style === NumberFormatStyle.Percent ? 1234.56 : 123456) this.locale = locale this.style = style diff --git a/tests/unit/numberFormat.spec.ts b/tests/unit/numberFormat.spec.ts index 6c42861..bc23d12 100644 --- a/tests/unit/numberFormat.spec.ts +++ b/tests/unit/numberFormat.spec.ts @@ -550,5 +550,25 @@ describe('NumberFormat', () => { ).toMatchSnapshot() }) }) + + describe('percent', () => { + describe('parse', () => { + it('should parse a formatted number', () => { + expect( + new NumberFormat({ + formatStyle: NumberFormatStyle.Percent, + locale: 'en' + }).parse('1234') + ).toBe(12.34) + + expect( + new NumberFormat({ + formatStyle: NumberFormatStyle.Percent, + locale: 'en' + }).parse('123,400%') + ).toBe(1234) + }) + }) + }) }) })