round(x: number,n?: number,): number
Round to nearest integer.
Rounds each element in x to the nearest integer or specified number of decimal places. Handles numbers, arrays, and matrices element-wise.
Round a number to 12 decimal places
Round a number to 12 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(Math.PI, 12), 3.14159265359);
Round an array of numbers to 2 decimal places
Round an array of numbers to 2 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.4543, 4.5234], 2), [-1.45, 4.52]);
Round an array of numbers to the nearest integer
Round an array of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.9, -0.2, 3.4, 5.6, 7.0]), [-2, 0, 3, 6, 7]);
Round a matrix of numbers to the nearest integer
Round a matrix of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.45, -2.3], [1.1, -4.3]]), [[1, -2], [1, -4]]);
Round a matrix of numbers to 1 decimal place
Round a matrix of numbers to 1 decimal place
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.456, -2.354], [1.123, -4.345]], 1), [[1.5, -2.4], [1.1, -4.3]]);
Round a single number without specifying decimal places
Round a single number without specifying decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(5.678), 6);
round(x: array,n?: number,): array
Round to nearest integer.
Rounds each element in x to the nearest integer or specified number of decimal places. Handles numbers, arrays, and matrices element-wise.
Round a number to 12 decimal places
Round a number to 12 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(Math.PI, 12), 3.14159265359);
Round an array of numbers to 2 decimal places
Round an array of numbers to 2 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.4543, 4.5234], 2), [-1.45, 4.52]);
Round an array of numbers to the nearest integer
Round an array of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.9, -0.2, 3.4, 5.6, 7.0]), [-2, 0, 3, 6, 7]);
Round a matrix of numbers to the nearest integer
Round a matrix of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.45, -2.3], [1.1, -4.3]]), [[1, -2], [1, -4]]);
Round a matrix of numbers to 1 decimal place
Round a matrix of numbers to 1 decimal place
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.456, -2.354], [1.123, -4.345]], 1), [[1.5, -2.4], [1.1, -4.3]]);
Round a single number without specifying decimal places
Round a single number without specifying decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(5.678), 6);
x: array
The value(s) to be rounded
The rounded value(s)
round(x: matrix,n?: number,): matrix
Round to nearest integer.
Rounds each element in x to the nearest integer or specified number of decimal places. Handles numbers, arrays, and matrices element-wise.
Round a number to 12 decimal places
Round a number to 12 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(Math.PI, 12), 3.14159265359);
Round an array of numbers to 2 decimal places
Round an array of numbers to 2 decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.4543, 4.5234], 2), [-1.45, 4.52]);
Round an array of numbers to the nearest integer
Round an array of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([-1.9, -0.2, 3.4, 5.6, 7.0]), [-2, 0, 3, 6, 7]);
Round a matrix of numbers to the nearest integer
Round a matrix of numbers to the nearest integer
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.45, -2.3], [1.1, -4.3]]), [[1, -2], [1, -4]]);
Round a matrix of numbers to 1 decimal place
Round a matrix of numbers to 1 decimal place
import { assertEquals } from "jsr:@std/assert"; assertEquals(round([[1.456, -2.354], [1.123, -4.345]], 1), [[1.5, -2.4], [1.1, -4.3]]);
Round a single number without specifying decimal places
Round a single number without specifying decimal places
import { assertEquals } from "jsr:@std/assert"; assertEquals(round(5.678), 6);
x: matrix
The value(s) to be rounded
The rounded value(s)