Try This and Comment | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Try This and Comment

if ((0.1+0.2)==0.3) { echo "0.1 + 0.2 is equal to 0.3"; }else{ echo "0.1 + 0.2 is not equal to 0.3"; }

27th Dec 2016, 12:52 PM
Guilherme Rodrigues
Guilherme Rodrigues - avatar
3 Answers
+ 1
Floating point representation of a number is always an approximation. So, 0.1 + 0.2 gives you 0.30000000000000004. That is why you should never compare floating point numbers with the equality/inequality operators
5th Jan 2017, 11:58 PM
soulaymanove
0
and to understand my answer more make an echo to this code : echo ((0.1+0.2)-0.3) ; and see the result 😊
6th Jan 2017, 12:00 AM
soulaymanove
0
i van say floating number is sensitive
21st Feb 2017, 1:11 PM
Fabien Godcoder
Fabien Godcoder - avatar