Locale-Sensitive JavaScript Method
number.toFixed();
number.toFixed(digits);
Internationalization (I18n) Method Overview
The toFixed method formats a number with the specified number of digits after the decimal point, rounding as needed.
For example:
var num = 123.567;
var result1 = num.toFixed();
var result2 = num.toFixed(2);
var result3 = num.toFixed(4);
Method returns:
result1: 124
result2: 123.57
result3: 123.5670
Click here (w3schools) and
here (MDN) for additional details.
I18n Issues
Whether or not calling toFixed 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 toFixed 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
|