How can I round down a number in Javascript?

Ben Shelock picture Ben Shelock · Sep 17, 2009 · Viewed 188.7k times · Source

How can I round down a number in JavaScript?

math.round() doesn't work because it rounds it to the nearest decimal.

I'm not sure if there is a better way of doing it other than breaking it apart at the decimal point at keeping the first bit. There must be...

Answer

phoebus picture phoebus · Sep 17, 2009

Using Math.floor() is one way of doing this.

More information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor