import { BigNumber } from "https://deno.land/x/web3@v0.11.1/types/bignumber.d.ts";
Returns a string representing the value of this BigNumber rounded to significantDigits
significant digits using rounding mode roundingMode
.
If significantDigits
is less than the number of digits necessary to represent the integer
part of the value in normal (fixed-point) notation, then exponential notation is used.
If significantDigits
is omitted, or is null
or undefined
, then the return value is the
same as n.toString()
.
If roundingMode
is omitted or is null
or undefined
, ROUNDING_MODE
is used.
Throws if significantDigits
or roundingMode
is invalid.
x = 45.6
y = new BigNumber(x)
x.toPrecision() // '45.6'
y.toPrecision() // '45.6'
x.toPrecision(1) // '5e+1'
y.toPrecision(1) // '5e+1'
y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP)
y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN)
x.toPrecision(5) // '45.600'
y.toPrecision(5) // '45.600'