Number Conversion and Formatting Methods
Working with numbers in real applications almost always involves converting between strings and numbers, or formatting a number for display. JavaScript provides both instance methods on number values and static functions to handle these conversions.
toFixed(digits)
Called on a number value, toFixed(n) returns a string representation rounded to n decimal places. It is the standard way to display currency or measurements. Note that it returns a string, not a number.
parseInt and parseFloat
parseInt(string, radix) parses a string and returns an integer. Always supply the radix (base) argument — omitting it can cause parseInt to mis-detect octal or hexadecimal prefixes in older environments. parseFloat parses a floating-point number from a string, stopping at the first character it cannot convert.
Number()
The Number() function converts any value to a number. Unlike parseInt, it does not tolerate trailing non-numeric characters — Number('42px') returns NaN while parseInt('42px') returns 42.