Skip to content

Commit

Permalink
feat(i18n): add the ability to specify minimum and maximum fraction d…
Browse files Browse the repository at this point in the history
…igits when formating number
  • Loading branch information
pdesoyres-cc committed Nov 29, 2023
1 parent f303993 commit e101776
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/i18n-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
* Format a given number
* @param {String} lang - BCP 47 language tag
* @param {Number} value
* @param {Object} options
* @param {Number} options.minimumFractionDigits
* @param {Number} options.maximumFractionDigits
* @returns {String}
*/
export function formatNumber (lang, value) {
const nf = new Intl.NumberFormat(lang);
export function formatNumber (lang, value, options = {}) {
const { minimumFractionDigits, maximumFractionDigits } = options;
const nf = new Intl.NumberFormat(lang, {
minimumFractionDigits,
maximumFractionDigits,
});
return nf.format(value);
}

Expand Down

0 comments on commit e101776

Please sign in to comment.