Best practice for fix point math and decimal conversion

Hey guys! I’m currently designing a smart contract with some fix point arithmetic. I’m wondering if there’s any best practice or good pattern that you guys’ve seen, we would love to adopt them.

Also we want to design an interface that unify all ERC20 decimals, so ideally in our system everything have the same decimals. Would love some feedback on this idea as well, thanks!

1 Like

Hi @antoncoding,

I suggest having a look the discussion in Designing Fixed Point Math in OpenZeppelin Contracts for some potential ideas.

As for ERC20 decimals there were a couple of relevant posts in the discussion:

I'm interested to hear from other members of the community on this topic.

Hi @antoncoding,

I also suggest looking at the List of Solidity libraries in the wild. There are a number of Fixed Point Arithmetic libraries.