Co-authored-by: Mikhail Bashkirov <mikhail.bashkirov@ing.com> Co-authored-by: Thijs Louisse <thijs.louisse@ing.com> Co-authored-by: Joren Broekema <joren.broekema@ing.com> Co-authored-by: Gerjan van Geest <gerjan.van.geest@ing.com> Co-authored-by: Erik Kroes <erik.kroes@ing.com> Co-authored-by: Lars den Bakker <lars.den.bakker@ing.com>
25 lines
745 B
JavaScript
25 lines
745 B
JavaScript
import { formatNumber, getFractionDigits } from '@lion/localize';
|
|
|
|
/**
|
|
* Formats a number considering the default fraction digits provided by Intl
|
|
*
|
|
* @param {float} modelValue Number to format
|
|
* @param {object} givenOptions Options for Intl
|
|
*/
|
|
export function formatAmount(modelValue, givenOptions) {
|
|
if (modelValue === '') {
|
|
return '';
|
|
}
|
|
const options = {
|
|
currency: 'EUR',
|
|
...givenOptions,
|
|
};
|
|
if (typeof options.minimumFractionDigits === 'undefined') {
|
|
options.minimumFractionDigits = getFractionDigits(options.currency);
|
|
}
|
|
if (typeof options.maximumFractionDigits === 'undefined') {
|
|
options.maximumFractionDigits = getFractionDigits(options.currency);
|
|
}
|
|
|
|
return formatNumber(modelValue, options);
|
|
}
|