roundTo
import { roundTo } from "jsr:@ende/math";function
function roundTo(num: number, digits: number, options?: RoundingOptions): numberRound a number to a specified number of digits.
num: numberThe number to be rounded
digits: numberThe number of digits to round to
options?: RoundingOptionsOptions for rounding
Returns
The rounded number
Example: Usage
import { roundTo } from "@ende/math/round-to";
import { assertEquals } from "@ende/assert";
assertEquals(roundTo(Math.PI, 2), 3.14);
assertEquals(roundTo(Math.PI, 2, { strategy: "ceil" }), 3.15);
assertEquals(roundTo(Math.PI, 3), 3.142);
assertEquals(roundTo(Math.PI, 3, { strategy: "floor" }), 3.141);
assertEquals(roundTo(-Math.PI, 3, { strategy: "trunc" }), -3.141);