Améliore le formatage des montants en euro

Fixes #725
pull/728/head
Maxime Quandalle 2019-10-10 14:13:30 +02:00
parent 545e1cef69
commit c3b465bdef
1 changed files with 13 additions and 3 deletions

View File

@ -11,13 +11,23 @@ export let numberFormatter = ({
maximumFractionDigits = 2,
minimumFractionDigits = 0,
language
}) => value =>
NumberFormat(language, {
}) => value => {
// When we format currency we don't want to display a single decimal digit
// ie 8,1€ but we want to display 8,10€
const adaptedMinimumFractionDigits =
style === 'currency' &&
maximumFractionDigits >= 2 &&
minimumFractionDigits === 0 &&
!Number.isInteger(value)
? 2
: minimumFractionDigits
return NumberFormat(language, {
style,
currency: 'EUR',
maximumFractionDigits,
minimumFractionDigits
minimumFractionDigits: adaptedMinimumFractionDigits
}).format(value)
}
export const currencyFormat = language => ({
isCurrencyPrefixed: !!numberFormatter({ language, style: 'currency' })(