function floor
floor(
x: number,
n?: number,
): number

Rounds toward negative infinity.

Rounds the input value(s) towards negative infinity, optionally to a specified number of decimal places.

Examples

Round PI to 12 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(Math.PI, 12), 3.141592653589);

Round a single number toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(3.78), 3);

Round an array of numbers toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([4.51, -1.4]), [4, -2]);

Round a matrix of numbers to 2 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([[4.5134, -1.4345], [3.7809, 0.0134]], 2), [[4.51, -1.44], [3.78, 0.01]]);

Parameters

x: number

Value(s) to be rounded

optional
n: number

Number of decimal places to round to (defaults to 0)

Return Type

number

The rounded value(s)

Throws

If no arguments are provided

floor(
x: array,
n?: number,
): array

Rounds toward negative infinity.

Rounds the input value(s) towards negative infinity, optionally to a specified number of decimal places.

Examples

Round PI to 12 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(Math.PI, 12), 3.141592653589);

Round a single number toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(3.78), 3);

Round an array of numbers toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([4.51, -1.4]), [4, -2]);

Round a matrix of numbers to 2 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([[4.5134, -1.4345], [3.7809, 0.0134]], 2), [[4.51, -1.44], [3.78, 0.01]]);

Parameters

Value(s) to be rounded

optional
n: number

Number of decimal places to round to (defaults to 0)

Return Type

The rounded value(s)

Throws

If no arguments are provided

floor(
x: matrix,
n?: number,
): matrix

Rounds toward negative infinity.

Rounds the input value(s) towards negative infinity, optionally to a specified number of decimal places.

Examples

Round PI to 12 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(Math.PI, 12), 3.141592653589);

Round a single number toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor(3.78), 3);

Round an array of numbers toward negative infinity

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([4.51, -1.4]), [4, -2]);

Round a matrix of numbers to 2 decimal places

import { assertEquals } from "jsr:@std/assert";

assertEquals(floor([[4.5134, -1.4345], [3.7809, 0.0134]], 2), [[4.51, -1.44], [3.78, 0.01]]);

Parameters

Value(s) to be rounded

optional
n: number

Number of decimal places to round to (defaults to 0)

Return Type

The rounded value(s)

Throws

If no arguments are provided