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,
  }
}
