Number Methods
Number methods help you shape and check numbers.
You can round them, fix decimals, or test if a value is safe.
Think of measuring cups and rulers for numbers.
toFixed and toString
Rounding helpers
isNaN and isFinite
parseFloat
toFixed
toFixed makes a string with a set number of decimals.
Handy for money style display.
toString
toString turns a number into text.
You can even pick another base, like binary.
Math.round, floor, ceil
These live on Math, but they work with numbers every day.
round goes to nearest. floor goes down. ceil goes up.
Number.isNaN
Number.isNaN checks for NaN carefully.
Number.isFinite
This asks if a value is a normal finite number.
Infinity and NaN fail the test.
parseFloat
parseFloat reads a decimal number from the start of a string.
Tip: Remember toFixed returns a string. Convert back with Number if you need more math.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.