Functions
convertToNumber
Converts a BigNumber to a JavaScript number with specified precision.BN
required
The BigNumber value to convert
BN
default:"PRICE_PRECISION"
The precision to use for conversion. Defaults to PRICE_PRECISION
number
The converted number value. Returns 0 if bigNumber is falsy
Usage Example
convertToBN
Converts a JavaScript number to a BigNumber with specified precision.number
required
The number value to convert
BN
required
The precision to use for conversion (e.g., PRICE_PRECISION, BASE_PRECISION)
BN
The converted BigNumber value
Usage Example
Implementation Details
The conversion functions properly handle:- Whole and decimal parts separately to maintain precision
- Division and modulo operations to extract components
- Rounding of decimal parts using
Math.round()andMath.floor() - Zero and null values