Web3 BigNumber is an extensive library for managing large number for Javascript and Node.js. Useful for web3 development.
npm install web3-bignumberbash
npm install web3-bignumber
`
$3
`bash
yarn add web3-bignumber
`
Getting Started
- :writing_hand: If you have questions submit an issue
Prerequisites
- :gear: NodeJS (LTS/Fermium)
- :toolbox: Yarn/Lerna
Usage
$3
`ts
const { Web3BigNumber } = require("web3-bignumber");
OR
import { Web3BigNumber } from "web3-bignumber";
`
`ts
Web3BigNumber(number: bigint | string | number)
`
---
$3
---
#### Simple Formatting
`ts
Web3BigNumber(1e+27).value();
// Output: 1000000000000000000000000000
`
#### From small to big
`ts
Web3BigNumber(1000).toBig(18);
// Output: 1000000000000000000000
`
#### From big to small
`ts
Web3BigNumber("12300000000000000").toSmall(18);
// Output: 0.0123
`
---
$3
---
#### Addition
`ts
Web3BigNumber("100").add(50);
// Output: 150
`
#### Subtract
`ts
Web3BigNumber("100").subtract(50);
// Output: 50
`
#### Multiply
`ts
Web3BigNumber("100").multiply(5);
// Output: 500
`
#### Division
`ts
Web3BigNumber("50").divide(5);
// Output: 10
`
---
$3
---
#### To Big Integer
`ts
Web3BigNumber("1234500000000000").toBigInt();
// Output: 1234500000000000n
`
#### To Integer
`ts
Web3BigNumber("123").toInteger();
// Output: 123
`
#### Comma Seperated
`ts
Web3BigNumber("1234500000000").toCommaSeparated();
// Output: 1,234,500,000,000
`
#### Compact Number
`ts
Web3BigNumber("1000000").toCompactNumber();
// Output: 1M
`
#### Percentage
`ts
Web3BigNumber("0.123").toPercent();
// Output: 12.3%
`
#### Fixed Decimal Places
`ts
Web3BigNumber("12.34567").trimDecimalPlaces(2);
// Output: 12.35
`
---
$3
---
#### Check Zero
`ts
Web3BigNumber(0).isZero();
// Output: true
Web3BigNumber(1).isZero();
// Output: false
`
#### Check Negative
`ts
Web3BigNumber(-123).isNegative();
// Output: true
Web3BigNumber(123).isNegative();
// Output: false
`
#### Equal
`ts
Web3BigNumber(123).equals("123");
// Output: true
Web3BigNumber(123).equals(456);
// Output: false
`
#### Greater Than
`ts
Web3BigNumber(123).gt("5");
// Output: true
Web3BigNumber(123).gt(456);
// Output: false
`
#### Greater Than or Equal
`ts
Web3BigNumber(123).gte("123");
// Output: true
Web3BigNumber(123).gte(456);
// Output: false
`
#### Less Than
`ts
Web3BigNumber(123).lt("1234");
// Output: true
Web3BigNumber(123).lt(5);
// Output: false
`
#### Less Than or Equal
`ts
Web3BigNumber(123).lte("123");
// Output: true
Web3BigNumber(123).lte(5);
// Output: false
`
#### Check Maximum
`ts
Web3BigNumber(123).max("1234");
// Output: 1234
`
#### Check Minimum
`ts
Web3BigNumber(123).min("1234");
// Output: 123
`
$3
`ts
// Example
Web3BigNumber(1000).subtract("1000").isZero();
// Output: true
`
---
#### All Prototype Functions
---
##### String | Number | BigInt
- 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) `