17 lines
502 B
JavaScript
17 lines
502 B
JavaScript
import { formatNumberToParts } from './formatNumberToParts.js';
|
|
|
|
/**
|
|
* @example
|
|
* getFractionDigits('JOD'); // return 3
|
|
*
|
|
* @param {string} currency Currency code e.g. EUR
|
|
* @return {number} fraction for the given currency
|
|
*/
|
|
export function getFractionDigits(currency = 'EUR') {
|
|
const parts = formatNumberToParts(123, {
|
|
style: 'currency',
|
|
currency,
|
|
});
|
|
const [fractionPart] = parts.filter(part => part.type === 'fraction');
|
|
return fractionPart ? fractionPart.value.length : 0;
|
|
}
|