Skip to content

Commit

Permalink
fix: decimal/grouping separator not detected in percent format style
Browse files Browse the repository at this point in the history
  • Loading branch information
dm4t2 committed Oct 30, 2021
1 parent d54ca88 commit bb81ba0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/numberFormat.ts
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/numberFormat.spec.ts
Expand Up @@ -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)
})
})
})
})
})

0 comments on commit bb81ba0

Please sign in to comment.