UNPKG

@0xtorch/big-decimal

Version:

An arbitrary precision Decimal type for TypeScript that extends BigInt.

18 lines (16 loc) 356 B
import type { BigDecimal } from './type' export const removeTrailingZeros = ({ value, decimals, }: BigDecimal): BigDecimal => { let mut_value = value let mut_decimals = decimals while (mut_value % 10n === 0n && mut_decimals > 0) { mut_value /= 10n mut_decimals -= 1 } return { value: mut_value, decimals: mut_decimals, } }