globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 605 forks source link

formatUnit does not display the formatted number when using a compound unit pattern #838

Closed EdwardSalter closed 6 years ago

EdwardSalter commented 6 years ago

When using a unitFormatter that takes a custom numberFormatter as an option, the formatter is called but the output is not used. The number is dumped directly into the returned message instead of using the formatted value.

The following example illustrates an example.

var customNumberFormatter = Globalize('fr').numberFormatter({ maximumFractionDigits: 1 });
var metersPerLiter = formatUnit(1.234567, 'meter-per-liter', { form: 'narrow', numberFormatter: customNumberFormatter });
var milesPerHour = formatUnit(1.234567, 'mile-per-hour', { form: 'narrow', numberFormatter: customNumberFormatter });

assert(metersPerLiter).toBe('1,2m/l');  // Fails as metersPerLiter === '1.234567m/l' - note the period (.) instead of comma (,) too.
assert(milesPerHour).toBe('1,2mph'); // True