1

I understand you cant represent them while writing the code, but are floating-point numbers rounded during the compilation?

Imagine there is an equation in code, that needs some sort of floating-point number, I.e 0.1. Since we can't write this directly, can we divide 10 on 100 to produce 0.1? Will compiler round this down to 0?

P.S I'm well aware of libraries mentioned here https://ethereum.stackexchange.com/a/83786/64937, but in my case, I don't want that much flexibility and complexity, but eventually, if there is no way I will use them.

2

The compiler does accept decimals in an expression if the resulting value is valid.

For example uint256 x = 0.23 * 100 is valid. The expression uint256 y = 0.123 * 100 fails to compile with

TypeError: Type rational_const 123 / 10 is not implicitly convertible to expected type uint256.

0

Imagine there is an equation in code, that needs some sort of floating-point number, I.e 0.1.

There are no floating-point literals in Solidity the language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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