Bug 1406375 - always localize numbers in l10n::numbersWithDecimals;r=Honza

With the previous implementation, zeros and integers passed to
numberWithDecimals would not be formatted according to the
locale.

This updates the method to make the formatting consistent,
regardless of the number argument.

MozReview-Commit-ID: KvU1AjhzXAf

--HG--
extra : rebase_source : 551faa5318c4b38b80ee4858e0dd473e6f0617c5
This commit is contained in:
Julian Descottes 2017-10-06 15:14:56 +02:00
Родитель 3ec8ed626a
Коммит 4980535bfe
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -151,13 +151,14 @@ LocalizationHelper.prototype = {
* The localized number as a string.
*/
numberWithDecimals: function (number, decimals = 0) {
// If this is an integer, don't do anything special.
// Do not show decimals for integers.
if (number === (number|0)) {
return number;
return getNumberFormatter(0).format(number);
}
// If this isn't a number (and yes, `isNaN(null)` is false), return zero.
if (isNaN(number) || number === null) {
return "0";
return getNumberFormatter(0).format(0);
}
// Localize the number using a memoized Intl.NumberFormat formatter.