@lion/localize
Version:
The localization system helps to manage localization data split into locales and automate its loading
21 lines (19 loc) • 650 B
JavaScript
import { formatNumberToParts } from './formatNumberToParts.js';
/**
* @example
* getFractionDigits('JOD'); // return 3
*
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart
* @param {string} [currency="EUR"] Currency code e.g. EUR
* @returns {number} fraction for the given currency
*/
export function getFractionDigits(currency = 'EUR') {
const parts = /** @type {FormatNumberPart[]} */ (
formatNumberToParts(123, {
style: 'currency',
currency,
})
);
const [fractionPart] = parts.filter(part => part.type === 'fraction');
return fractionPart ? fractionPart.value.length : 0;
}