New to blockchain software development? Read my beginners guide here

How to do floating point/decimal math in Solidity

Created on August 2022 β€’ Tags: solidityguides

A guide on working with decimals in Solidity

Solidity has no concept of floating point numbers. But you can still do decimal math in Solidity.

The easiest way is to use a library. A commonly used one is ABDKMathQuad.

https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMathQuad.md

(use it at your own risk, this post is for educational purposes only. I have not verified if that package is legit, accurate or safe to use.)

Also see my post on math functions in Solidity and percentages in Solidity code

This post is incomplete and a work-in-progress
I'll update it soon and flesh it out with more info!

Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!

See all posts (70+ more)

See all posts (70+ more)

Was this post helpful? πŸ“§

If you liked this content and want to receive emails about future posts like this, enter your email. I'll never spam you.

Or follow me on @CryptoGuide_Dev on twitter

By using this site, you agree that you have read and understand its Privacy Policy and Terms of Use.
Use any information on this site at your own risk, I take no responsibility for the accuracy of safety of the information on this site.