MoreLesson 232Free preview
Remove Decimals
This lesson is part of How To · All levels
Summary
Removing decimals means turning a fractional number into an integer, for example 12.75 to 12. JavaScript provides Math.trunc to cut the decimal point, Math.floor to round down, and Math.round to round to nearby. The choice of method depends on whether you want to cut, round, or keep the negative value.
Key points
- Cut the decimal without dipping
- Math.floor() round down, as opposed to truncating to negative numbers
- Math.round() round to the nearest integer
- Return the string and do the drill, not just cut it.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.