there is something i do not understand in Vyper documentation:


Binary fixed point: Decimal fixed point is better, because any decimal fixed point value written as a literal in code has an exact representation, whereas with binary fixed point approximations are often required (e.g. (0.2)10 = (0.001100110011…)2, which needs to be truncated), leading to unintuitive results, e.g. in Python 0.3 + 0.3 + 0.3 + 0.1 != 1.

They talk about "binary fixed point" and "Decimal fixed point". I do not understand the difference between.

For me there are 2 technologies: Floating point and Fixed point.

What i have understood is Vyper works with fixed point technology.

I do not understand why they are talking about "Binary" and "Decimal" fixed point.

Thanks a lot

1 Answer 1


You can use base 2 or base 10 number for your fixed-point mathematics.

For fiat currency financial calculations base 10 makes sense, as you get nice round cents like $102.13 instead of e.g. $102.1222222222222229.

Alternatively, we can have unit be a power of two. This has two big benefits: We can use shifts instead of multiplications and divisions, which are cheaper in gas (see note at the end!). The numbers are easier to reason about regarding ranges and overflow protection, making the library simpler/safer.

The downside is our numbers will no longer behave like decimal point numbers. For example, if unit = 2^2 = 4, then the smallest number would be 0.25, not 0.1 or 0.01. I’d argue however that this value will be so small that this won’t be an issue.

From Solidity fixed point discussion.

Wikipedia can also answer to your question

  • 1
    Thanks. I am sorry but i do not understand. I have already read your wikipedia article. I do not understand this idea of base 2/10. On a CPU, everything is binary, base 2 (0/1)
    – Bob5421
    Commented Jan 29, 2021 at 12:57
  • Then this goes to be a math question. Commented Jan 29, 2021 at 14:07
  • Let's put this way: For example you cannot represent number "10.02" as binary fixed point, but you can present it as a decimal fixed point. Commented Jan 29, 2021 at 14:15
  • Let me try to find you a matching tutorial article in Solidity, because people have been solving this problem all over multiple times for some years now. Commented Jan 29, 2021 at 14:25
  • Hopefully this helps forum.openzeppelin.com/t/… Commented Jan 29, 2021 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.