0
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

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
velpandian
  • 431
  • 4
  • 11
  • 23

1 Answers1

4

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?

Community
  • 1
  • 1
slebetman
  • 109,858
  • 19
  • 140
  • 171