Ethereum: How multiplication and division works in solidity?

Ethereum: How Multiplication and Division in Solitude Work

======== goods ===== ===============

In solidarity, the order of operations is crucial for the calculations of accessories. Two common arithmetic operations that can lead to confusion are multiplication and division. Solidness, more specially focusing on how they are calculated.

Advantage and order of operations

—————————–

Evil follows a specific rule of advantage when it comes to arithmetic operations:

  • Brackets: First evaluate the expressions inside the brackets.

  • Exponents (eg **): Rate all exponents afterwards.

  • Multiplication and division (eg 2 * 3): Order is multiplication before division.

4.

Let’s look at the example you have provided:

`Solidity

Amount = (15-10) 10/15 (10000 - 5000) / 10000;

Demolition of this expression, we can follow the rules of transrson:

  • Rate the expressions inside brackets: (15-10) and (10000 - 5000)

* 15-10 = 5 (exposure is not applicable)

* 10000 - 5000 = 5000 (Exponance is not applicable)

  • Multiply 5 by ’10:5 * 10 = 50

3

4.

So the correct calculation really has to be:

Amount = 50/15 * 5000/1 10000;

`

Not 5 * 10/15.

Common mistakes

—————

To avoid common errors when working with arithmetic operations in solidity:

  • Always evaluate first the expressions inside brackets.

2.

3

Best practices

—————

To write an accurate and effective solidity code:

1

  • Follow the order of advantage rules carefully.

S

Silistics, you will be able to write more accurate and reliable intelligent contracts that benefit from the unique functions of the language.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *