Round Down a Number in JavaScript

Deepak Prasad

Rounding down in JavaScript usually means dropping the fractional part and keeping the lower whole number. The common methods are Math.floor(), Math.trunc(), and sometimes Math.round() when the decimal value is already below 0.5.

The method you choose depends on whether you want a strict round-down rule or simple truncation. If you later need the opposite direction, Math.ceil in JavaScript is the natural companion topic.

Tested on: Node.js v20.18.2. A short note after each runnable snippet describes what you should see in the console.


Method 1: Round down with Math.floor()

Math.floor() always returns the lower integer.

javascript
console.log("round-down-1:", Math.floor(4.98));
console.log("round-down-neg:", Math.floor(-4.98));
Output

You should see 2 lines, in order: round-down-1: 4, round-down-neg: -5.

This is the most common method when you want a guaranteed round-down result.


Method 2: Truncate the decimal part with Math.trunc()

Math.trunc() removes the decimal part and keeps the integer closer to zero.

javascript
console.log("round-down-2:", Math.trunc(4.98));
console.log("round-down-trunc-neg:", Math.trunc(-4.98));
Output

You should see 2 lines, in order: round-down-2: 4, round-down-trunc-neg: -4.

Use this when you want truncation rather than mathematical floor behavior.


Method 3: Compare round(), floor(), and trunc()

Math.round() is not a pure round-down method, but it helps you see the difference.

javascript
console.log("round-down-round:", Math.round(4.49));
console.log("round-down-floor:", Math.floor(4.49));
console.log("round-down-trunc:", Math.trunc(4.49));
Output

You should see 3 lines, in order: round-down-round: 4, round-down-floor: 4, round-down-trunc: 4.

This comparison makes the rounding behavior clear when you are choosing the right method.


Summary

To round down numbers in JavaScript, use Math.floor() when you want the lower integer and Math.trunc() when you want to remove the decimal part. Math.round() is useful for comparison, but it is not the right tool for consistent round-down behavior.


Official documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs user-friendly interfaces to enhance digital experiences across various domains.

  • JavaScript
  • Web Design