Web3 BigNumber is an extensive library for managing large number for Javascript and Node.js. Useful for web3 development.
You can install the package using NPM
npm install web3-bignumber
yarn add web3-bignumber
- ✍️ If you have questions submit an issue
const { Web3BigNumber } = require("web3-bignumber");
OR
import { Web3BigNumber } from "web3-bignumber";
Web3BigNumber(number: bigint | string | number)
Web3BigNumber(1e+27).value();
// Output: 1000000000000000000000000000
Web3BigNumber(1000).toBig(18);
// Output: 1000000000000000000000
Web3BigNumber("12300000000000000").toSmall(18);
// Output: 0.0123
Web3BigNumber("100").add(50);
// Output: 150
Web3BigNumber("100").subtract(50);
// Output: 50
Web3BigNumber("100").multiply(5);
// Output: 500
Web3BigNumber("50").divide(5);
// Output: 10
Web3BigNumber("1234500000000000").toBigInt();
// Output: 1234500000000000n
Web3BigNumber("123").toInteger();
// Output: 123
Web3BigNumber("1234500000000").toCommaSeparated();
// Output: 1,234,500,000,000
Web3BigNumber("1000000").toCompactNumber();
// Output: 1M
Web3BigNumber("0.123").toPercent();
// Output: 12.3%
Web3BigNumber("12.34567").trimDecimalPlaces(2);
// Output: 12.35
Web3BigNumber(0).isZero();
// Output: true
Web3BigNumber(1).isZero();
// Output: false
Web3BigNumber(-123).isNegative();
// Output: true
Web3BigNumber(123).isNegative();
// Output: false
Web3BigNumber(123).equals("123");
// Output: true
Web3BigNumber(123).equals(456);
// Output: false
Web3BigNumber(123).gt("5");
// Output: true
Web3BigNumber(123).gt(456);
// Output: false
Web3BigNumber(123).gte("123");
// Output: true
Web3BigNumber(123).gte(456);
// Output: false
Web3BigNumber(123).lt("1234");
// Output: true
Web3BigNumber(123).lt(5);
// Output: false
Web3BigNumber(123).lte("123");
// Output: true
Web3BigNumber(123).lte(5);
// Output: false
Web3BigNumber(123).max("1234");
// Output: 1234
Web3BigNumber(123).min("1234");
// Output: 123
// Example
Web3BigNumber(1000).subtract("1000").isZero();
// Output: true
toBigInt()
toCommaSeparated()
toCompactNumber()
toPercent()
toInteger()
isZero()
isNegative()
equals(num2: number | string | bigint)
gt(num2: number | string | bigint)
gte(num2: number | string | bigint)
lt(num2: number | string | bigint)
lte(num2: number | string | bigint)
add(num2: number | string | bigint)
subtract(num2: number | string | bigint)
multiply(num2: number | string | bigint)
divide(num2: number | string | bigint)
max(num2: number | string | bigint)
min(num2: number | string | bigint)