Reputation: 471
set number [expr {int(1.2/0.1)}]
puts $number
from the above am getting output as
"11"
Could someone explain how am getting this result using TCL
Upvotes: 0
Views: 143
Reputation: 113926
That's because 1.2/0.1 is 11.999999999999998. And int()
takes only the integer portion and discards the .999999999999998
part. So the answer becomes 11.
As for why it's 11.999999999999998, that's the behavior of floating point numbers. There's lots of questions on SO and on other parts of the internet about this so I'm going to point you to just one question: Is floating point math broken?
Upvotes: 4