1.06 is not a float. The closest float is 1.059999942779541015625. If
you multiply that by 100 you get a number that, again, is not a float.
Rounding to the nearest float yields 105.99999237060546875, which is the
result of the expression ver * 100
, and just one ULP short of 106.
Yes, floating point computations do quite usually involve rounding
steps.
Casting to an int
implicitly rounds towards zero, and you get 105,
which is the correct result. Correct according to the rules of IEEE 754
arithmetics.
You may want to round()
to the nearest integer before the cast.
Variable ver can be any decimal in this format x.xx
No, a float
cannot be “any decimal” in this format. Floats are stored
in binary, and most decimal numbers (numbers that can be written with a
finite number of decimal digits) cannot be written in binary with a
finite number of bits.
Except for a few values (namely the multiples of 0.25), ver
can only
store an approximation of the decimal number.