vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

Number Formatting: support BigInt and String in additional to Number

Open mahnunchik opened this issue 2 years ago • 3 comments

Clear and concise description of the problem

Intl.NumberFormat supports Number, BigInt, and String as a number parameter.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format

A Number, BigInt, or string, to format. Strings are parsed in the same way as in number conversion, except that format() will use the exact value that the string represents, avoiding loss of precision during implicitly conversion to a number.

Currently only number is supported in vue-i18n library: https://github.com/intlify/vue-i18n-next/blob/fa612d336e603cce237491eca092a7e856e4cb6c/packages/vue-i18n-core/src/components/NumberFormat.ts#L44-L47

Suggested solution

$n method should support the same types of parameter as underlying Intl.NumberFormat.prototype.format() method.

Alternative

No response

Additional context

  • BigInt parameter is useful for numbers exceed MAX_SAFE_INT numbers
  • String parameter is useful for number with many decimals places.

Validations

mahnunchik avatar Dec 07 '22 13:12 mahnunchik