Locale-Sensitive JavaScript Method
number.toExponential();
number.toExponential(digits);
Internationalization (I18n) Method Overview
The toExponential method formats a number in exponential notation, with the specified number of digits after the decimal point, rounding as needed.
For example:
var num = 123.567;
var result1 = num.toExponential();
var result = num.toExponential(2);
Method returns:
result1: 1.23567e2
result2: 1.24e2
Click here (w3schools) and
here (MDN) for additional details.
I18n Issues
Whether or not calling toExponential is an i18n issue is dependent on how it is being used in the application. If the number string is to
be displayed to a user, then using this method is a problem, since it will always display a period for the decimal separator.
Suggested Replacement
Don't use the toExponential method to format numbers that should be locale-dependent. Instead, use
the Intl.NumberFormat constructor which supports setting the locale and
then call its format method to format numbers based on the locale.
Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can
use Globalyzer's Ignore Comment
functionality to ensure that it isn't picked up in a subsequent scan.
Locale-Sensitive JavaScript Methods
|