-
Notifications
You must be signed in to change notification settings - Fork 27.5k
number filter converts null to "0" #6188
Comments
All unit tests pass after this change. It seems possible that the original behavior is intentional since JS itself treats 'null' like numeric 0. |
Personally I would prefer what the doc says where only numbers (possibly in a string) are formatted as numbers, and non numbers return a blank string. Even if that can't be done and null is converted to "0" I think all those other cases should return an empty string. |
We should use isNumber Angular function to check for a number, this is fix for this issue Line 457 in 686b13b
|
I thought using isNumber would be too strict, however I see you first called parseFloat. This fixes the original issue I brought up but now number leading strings will work such as "123foobar" where parseFloat returns 123. Was that intentional? |
…ings to the empty string The previous code for filtering out non-finite numbers was broken, as it would convert `null` to `0`, as well as arrays. This change fixes this by converting null/undefined/NaN/Infinity/any object to the empty string. Closes angular#6188 Closes angular#6261
The doc says the 'number' filter:
But passing many non-number values (null, "", " ", [], ...) return "0" because isNaN is broken.
I think the simple fix would be making the is-number check at the start of formatNumber() better, or if that is too risky of a change then the documentation should be updated. The jQuery isNumeric implementation might be best:
The text was updated successfully, but these errors were encountered: