@xylabs/decimal-precision
v5.0.86
Published
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Readme
@xylabs/decimal-precision
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Reference
@xylabs/decimal-precision
Functions
| Function | Description | | ------ | ------ | | fromFixedPoint | Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places. | | toDecimalPrecision | Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros. | | toFixedPoint | Converts a bigint or decimal string to a fixed-point bigint representation. |
functions
fromFixedPoint
function fromFixedPoint(value: bigint, places?: number): bigint;Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places.
Parameters
| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| value | bigint | undefined | The fixed-point bigint value to convert |
| places | number | 18 | Number of decimal places (default 18) |
Returns
bigint
The whole-number bigint result
toDecimalPrecision
function toDecimalPrecision(value: number, digits: number): string;Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros.
Parameters
| Parameter | Type | Description |
| ------ | ------ | ------ |
| value | number | The number to format |
| digits | number | The number of significant digits |
Returns
string
A string representation of the number with the specified precision
toFixedPoint
function toFixedPoint(value: string | bigint, places?: number): bigint;Converts a bigint or decimal string to a fixed-point bigint representation.
Parameters
| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| value | string | bigint | undefined | The value to convert (bigint or string with optional decimal point) |
| places | number | 18 | Number of decimal places (default 18) |
Returns
bigint
A bigint representing the value scaled by 10^places
Part of sdk-js
Maintainers
License
See the LICENSE file for license details
