UNPKG

@0xtorch/big-decimal

Version:

An arbitrary precision Decimal type for TypeScript that extends BigInt.

22 lines (18 loc) 589 B
import { fix } from './fix' import { removeTrailingZeros } from './removeTrailingZeros' import type { BigDecimal } from './type' export const times = ( x: BigDecimal, y: BigDecimal, fixDecimals?: number, rounding: 'round' | 'floor' | 'ceil' = 'round', ): BigDecimal => { // adjust the decimals and multiply the values. const decimals = x.decimals + y.decimals const value = x.value * y.value if (fixDecimals === undefined) { // remove trailing zeros. return removeTrailingZeros({ value, decimals }) } return fix({ value, decimals }, fixDecimals, rounding) }