This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Number Decimal Separator Incorrect for exponentially small numbers #10342
Closed
Description
Issue
The number decimal separator are incorrect for the fr-fr locale in formatNumber for exponentially small numbers.
Expected
- Decimal: ,
Actual
- Decimal: .
In fact, it's an issue for all languages that do not have a dot as decimal separator.
I suggest the same use case than "should filter exponentially small numbers" to test this issue:
it('should filter exponentially small numbers on non dot decimal separator languages', function() {
$locale.NUMBER_FORMATS.DECIMAL_SEP = ',';
expect(number(1e-50, 0)).toEqual('0');
expect(number(1e-6, 6)).toEqual('0,000001');
expect(number(1e-7, 6)).toEqual('0,000000');
expect(number(-1e-50, 0)).toEqual('0');
expect(number(-1e-6, 6)).toEqual('-0,000001');
expect(number(-1e-7, 6)).toEqual('-0,000000');
});
Solve suggestion
I figure out where the issue is localized: https://github.com/angular/angular.js/blob/g3_v1_3/src/ng/filter/filters.js#L206
if (fractionSize > 0 && number < 1) {
formatedText = number.toFixed(fractionSize);
number = parseFloat(formatedText);
}
The .toFixed
method is directly use to render the final number. And so, does NOT care about i18n at all.
To solve this issue, I suggest just to replace the dot by the expected decimal separator. As we deal this just number < 1, we don't have to manage thousand group separators.
if (fractionSize > 0 && number < 1) {
formatedText = number.toFixed(fractionSize);
number = parseFloat(formatedText);
formatedText = formatedText.replace(DECIMAL_SEP, decimalSep);
}