On this page
Math.floor
Prev: Math | Up: Math | Next: min
Rel: Math, JSON, Math, BigInt & Date Guide
Ref: MDN Web Docs — Math.floor
Tags: #public #web #javascript #builtins #math #tier/core
Signature & Overview
Math.floor(x) /* + ceil(), round(), trunc() */
Rounds x downward toward $-\infty$ (trunc() drops the fractional part toward 0).
Notes & Pitfalls
- Rounds toward $-\infty$:
Math.floor(-2.1)is-3, whereasMath.trunc(-2.1)is-2.
Example
console.assert(Math.floor(2.9) === 2);
console.assert(Math.floor(-2.1) === -3);
Linked from
Related notes
- tuts/javascript/builtins/Math/min Linked here; links to this page; shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Math Linked here; links to this page; shared tags: #builtins, #javascript, #math, #web
- tuts/javascript/builtins/json_math_and_date Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/Math/hypot shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Math/random shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/find shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/flatMap shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/from shared tags: #builtins, #javascript, #tier, #web