# Best practice for fix point math and decimal conversion

**URL:** <https://forum.openzeppelin.com/t/best-practice-for-fix-point-math-and-decimal-conversion/3367>\
**Category:** Security\
**Tags:** design\
**Created:** [July 22, 2020, 6:44am UTC](https://forum.openzeppelin.com/t/best-practice-for-fix-point-math-and-decimal-conversion/3367 "2020-07-22T06:44:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoncoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/antoncoding/32/1674_2.png) [@antoncoding](https://forum.openzeppelin.com/u/antoncoding)\
**Post date:** [July 22, 2020, 6:44am UTC](https://forum.openzeppelin.com/t/best-practice-for-fix-point-math-and-decimal-conversion/3367/1 "2020-07-22T06:44:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 22, 2020, 7:19am UTC](https://forum.openzeppelin.com/t/best-practice-for-fix-point-math-and-decimal-conversion/3367/2 "2020-07-22T07:19:26Z")

</div>

Hi @antoncoding,

I suggest having a look the discussion in [Designing Fixed Point Math in OpenZeppelin Contracts](https://forum.openzeppelin.com/t/designing-fixed-point-math-in-openzeppelin-contracts/2499) for some potential ideas.

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

> [@Designing Fixed Point Math in OpenZeppelin Contracts](https://forum.openzeppelin.com/t/designing-fixed-point-math-in-openzeppelin-contracts/2499/3):
>
> I found this list of token decimal breakdown by percentage ([https://github.com/ethereum/EIPs/issues/724#issuecomment-333155336](https://github.com/ethereum/EIPs/issues/724#issuecomment-333155336)). I looked at the original list and it seems like there aren’t any tokens with more than 18 decimals. Here’s the breakdown if you don’t want to follow the link: decimals Percent of tokens 0 10% 1 0.5% 2 3.1% 3 1.5% 4 1% 5 1% 6 2.6% 7 0.5% 8 21%…

> [@Designing Fixed Point Math in OpenZeppelin Contracts](https://forum.openzeppelin.com/t/designing-fixed-point-math-in-openzeppelin-contracts/2499/4):
>
> I would just note, that token decimals have nothing to do with fixed point math, as all token amounts are actually integers, and decimals property is just a hint for UI regarding how to present token amounts to a user.

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

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 27, 2020, 1:21am UTC](https://forum.openzeppelin.com/t/best-practice-for-fix-point-math-and-decimal-conversion/3367/3 "2020-07-27T01:21:51Z")

</div>

Hi @antoncoding,

I also suggest looking at the [List of Solidity libraries in the wild](https://forum.openzeppelin.com/t/list-of-solidity-libraries-in-the-wild/2250). There are a number of Fixed Point Arithmetic libraries.
