why this code gives 3.0000000000000004 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why this code gives 3.0000000000000004 ?

https://code.sololearn.com/W58tD25kA57C/?ref=app

20th Oct 2019, 8:42 AM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
6 Answers
+ 6
https://www.sololearn.com/discuss/1606645/?ref=app and of course, https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate
20th Oct 2019, 11:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hatsy Rei thanks for this start of explaination ;)
20th Oct 2019, 1:05 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
+ 1
Seb TheS thx. i will sleep less stupid to night with this knowledge...
20th Oct 2019, 1:18 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
0
thx for your answers Mirielle🐶 [Inactive] but how 0.1+0.2 give 0.30...4 ? it's not logic (mathematicly)
20th Oct 2019, 10:20 AM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
0
Oneill [HTML+JS+PHP] You need to know that computers store floats in binary. Some 10th base floats can not be converted to binary.
20th Oct 2019, 12:52 PM
Seb TheS
Seb TheS - avatar
0
Any float that can not be converted into a whole number by multiplicating it with 2 as many times as necessary, can not be completed in binary format.
20th Oct 2019, 1:09 PM
Seb TheS
Seb TheS - avatar