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

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

Deno / TypeScript to Ethereum Connector
Latest
method BigNumber.prototype.toString
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 base base, or base 10 if base is omitted or is null or undefined.

For bases above 10, and using the default base conversion alphabet (see ALPHABET), values from 10 to 35 are represented by a-z (the same as Number.prototype.toString).

If a base is specified the value is rounded according to the current DECIMAL_PLACES and ROUNDING_MODE settings, otherwise it is not.

If a base is not specified, and this BigNumber has a positive exponent that is equal to or greater than the positive component of the current EXPONENTIAL_AT setting, or a negative exponent equal to or less than the negative component of the setting, then exponential notation is returned.

If base is null or undefined it is ignored.

Throws if base is invalid.

x = new BigNumber(750000)
x.toString()                    // '750000'
BigNumber.config({ EXPONENTIAL_AT: 5 })
x.toString()                    // '7.5e+5'

y = new BigNumber(362.875)
y.toString(2)                   // '101101010.111'
y.toString(9)                   // '442.77777777777777777778'
y.toString(32)                  // 'ba.s'

BigNumber.config({ DECIMAL_PLACES: 4 });
z = new BigNumber('1.23456789')
z.toString()                    // '1.23456789'
z.toString(10)                  // '1.2346'

Parameters

optional
base: number

Returns

string