Last week I was lucky enough to go to ETHDenver and got to learn a ton of new developments in the Algorand Ecosystem, plus I got to know some brilliant people in the Algo ecosystem. I want to thank @barnji for showing me this repository for fixed-point arithmetic in Pyteal: pyteal-utils/fixed_point.py at fp-class · barnjamin/pyteal-utils · GitHub
I am having some trouble using the library in my code.
Goal: I want to divide two integers with a high degree of precision in order to get a percentage.
from pyteal import * from .fp_arithmetic import fp_div, fp_mul, fp_to_ascii def approval_program(): @Subroutine(TealType.none) def divide_func(): numerator = Int(90) denominator = Int(45000000000) numerator_bytes = Itob(numerator) denominator_bytes = Itob(denominator) division_result = fp_div(numerator_bytes, denominator_bytes) division_result_to_ascii = fp_to_ascii(division_result) return Seq([ Log( division_result_to_ascii ), ])
The smart contract logs:
What am I doing wrong?