What’s the best way to divide two Integers and maintain precision in Motoko, for example to divide two numbers with digits in the trillions.
In my specific case I want to get the percent adjustment from one number to the second number actual_value / expected_value
, with 1e12 precision.
Would it be to:
- Scale the numerator by 1e12
numerator * 1e12
- Do the Integer division
scaled numerator / divisor
- Convert the Integer to a Float
- Divide the Float result by 1e12.
Ideally this needs to be done on the backend.