1 Number.MAX_VALUE
When performing any arithmetic operations such as addition. Always check if the candidate number variables are not Nan. Otherwise, the result becomes a NaN.
1 2 3 | parseFloatReplaceNaNByZero(item) { return (!isNaN(parseFloat(item)) ? parseFloat(item) : 0) }, |
]]>
1
2
3
4
5
6
7
8
9 // Lodash to rescue
// Works exactly as we expect. Output is a typeof number.
_.round("10.608", 2); // 10.61
// Following returns the output as string. That's one major down side.
parseFloat("10").toFixed(2); // 10.00
parseFloat("10.60").toFixed(2); // 10.60
parseFloat("10.605").toFixed(2); // 10.61