Last active
July 17, 2024 13:59
-
-
Save srph/98661699d8e97a6ab57492383008122f to your computer and use it in GitHub Desktop.
JS/TS: Multiply BigInt to Float
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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