Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/web3/types/bignumber.d.ts>BigNumber#toExponential

Deno / TypeScript to Ethereum Connector
Latest
method BigNumber.prototype.toExponential
import { BigNumber } from "https://deno.land/x/web3@v0.11.1/types/bignumber.d.ts";

Returns a string representing the value of this BigNumber in exponential notation rounded using rounding mode roundingMode to decimalPlaces decimal places, i.e with one digit before the decimal point and decimalPlaces digits after it.

If the value of this BigNumber in exponential notation has fewer than decimalPlaces fraction digits, the return value will be appended with zeros accordingly.

If decimalPlaces is omitted, or is null or undefined, the number of digits after the decimal point defaults to the minimum number of digits necessary to represent the value exactly.

If roundingMode is omitted or is null or undefined, ROUNDING_MODE is used.

Throws if decimalPlaces or roundingMode is invalid.

x = 45.6
y = new BigNumber(x)
x.toExponential()               // '4.56e+1'
y.toExponential()               // '4.56e+1'
x.toExponential(0)              // '5e+1'
y.toExponential(0)              // '5e+1'
x.toExponential(1)              // '4.6e+1'
y.toExponential(1)              // '4.6e+1'
y.toExponential(1, 1)           // '4.5e+1'  (ROUND_DOWN)
x.toExponential(3)              // '4.560e+1'
y.toExponential(3)              // '4.560e+1'

Parameters

decimalPlaces: number
optional
roundingMode: BigNumber.RoundingMode

Returns

string

Returns

string