Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

Rounding errors with division

In the Solidity language, there is no official support for floating-point numbers. In the future, there will be support for floating-point numbers. Developers have to use unsigned uintX or signed intX integers only for their calculations. Hence, if any division operation is performed, the result of that calculation might have rounding errors. The result is always rounded down to the nearest integer.

Here is an example in the following code:

//Bad Practiceuint result = 5 / 2;

The preceding code would set value 2 in the result variable, as 2.5 rounded down to the nearest integer.

These rounding errors could cause problems when you are calculating some values that affect tokens, bonuses, or dividends. Hence, a developer ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content