Skip to content

Instantly share code, notes, and snippets.

@srph
Last active July 17, 2024 13:59
Show Gist options
  • Save srph/98661699d8e97a6ab57492383008122f to your computer and use it in GitHub Desktop.
Save srph/98661699d8e97a6ab57492383008122f to your computer and use it in GitHub Desktop.
JS/TS: Multiply BigInt to Float
// Bn -> Float multiplication works like this: 150e6 * (0.5 * 100) / 100
// Also does some coercions for readability
const multiplyBnToFloat = (a: string, b: string) => {
return (BigInt(a) * BigInt(Number(b) * 100)) / BigInt(100)
}
// 75000000
multiplyBnToFloat('150000000', '0.5000000000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment