export function toBaseUnits(amountHuman: string, decimals: number): string {
  const [intPart, fracRaw = ''] = amountHuman.split('.')
  const frac = fracRaw.slice(0, decimals).padEnd(decimals, '0')
  const combined = `${intPart}${frac}`.replace(/^0+(?=\d)/, '')
  return combined || '0'
}

export function fromBaseUnits(raw: string, decimals: number): string {
  const s = raw.padStart(decimals + 1, '0')
  const int = s.slice(0, s.length - decimals)
  const frac = s.slice(s.length - decimals).replace(/0+$/, '')
  return frac ? `${int}.${frac}` : int
}
