Skip to content
Advertisement

What is the Difference between Floor and Round

JavaScript

What are the difference.? when do I use floor() or round() for the number above.?

Advertisement

Answer

floor() will simply drop decimal value and return only integer.

So floor(1.2) => 1 and floor(1.9) => 1.

Meanwhile round() will round number that has decimal value lower than 0.5 to lower int, and when more than 0.5 to higher int:

So round(1.2) => 1 but round(1.9) => 2

Also round() has more options, like precision and rounding options.


Example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement