Skip to main content
Module

x/math/to_fixed.ts>toFixed

Deno module for high-precision calculations and scientific computing
Latest
function toFixed
import { toFixed } from "https://deno.land/x/math@v1.1.0/to_fixed.ts";

Returns a string representing the value of value in normal notation to a fixed number of dp decimal places. If the value of value in normal notation has more digits to the right of the decimal point than is specified by dp, the return value will be rounded to dp decimal places using rounding mode Big.RM. If the value of value in normal notation has fewer fraction digits then is specified by dp, the return value will be appended with zeros accordingly. Unlike Number.prototype.toFixed, which returns exponential notation if a number is greater or equal to 1021, this method will always return normal notation. Throws if value or dp is invalid.

Parameters

value: BigSource
optional
dp: number

integer, 0 to 1e+6 inclusive. If dp is omitted or is undefined, the return value is simply the value in normal notation. This is also unlike Number.prototype.toFixed, which returns the value to zero decimal places.

Returns

string