Remember decimal fraction values are not exactly represented in floating point which are
binary fractions. Thus 0.1 * 10 != 1.0 (or rather its not guaranteed to be equal).

So the loop end condition was hanging on a knife-edge when comparing a multiple of 0.1 against
5.0.

Anyway the other problem as pointed out above is that did not use round() when converting to int, which
is usually the way to fix things:

int i = n * 10;

Will hit the inexactness issue mentioned above some of the time - its basically undefined/ill-defined.

int i = round (n * 10);

Does what you want and will be far more robust.

The whole loop though is wrong - you should iterate with an integer, convert in the body to a float:

for (int i = 0; i < 50 ; i++){
float n = i / 10.0; // this is the only step with any imprecision now.
Serial.print(n);
Serial.print(" = ");
Serial.println(i);
}

Exercise for the reader: Why not change that second line to: float n = 0.1 * i; ?

Bronson_alex:
To spycatcher2k, westfw, PaulS and MarkT: Thanks for all your time & efforts.

Using "int i = round (n * 10);" solves the problem. Next time I will try not to use float var whenever possible.

To Holmes4: Why so hostile? FYI, 2.40*10 = 24 not 23. But thanks for your time anyway.

Regards
Bronson

What he was trying to get at was that you think you put the exact value 2.4 into that float. But floats don't hold exact values. They hold "close enough" values. So what he meant was that you were wrong to think that particular float times 10 would necessarily equal 24.

holmes4:
It is NOT a mis-calculation! YOU are the one that is wrong!

Mark

But its the computer that's wrong, of course. IEEE is inaccurate. The only fault is assuming that its easy
to be exact in mechanical calculation schemes for uncountable number types.

If you've ever used Common Lisp, you'll miss the automatic upgrading to rationals from integers on
division - Common Lisp can divide by any integer and doesn't overflow (unless there's insufficient RAM
to hold the result). However it has limits, many maths functions return floats...

Not in decimal, but it is ok with fractional numbers (is that the correct term?) ^{1}/_{3}.

Just because the silicon only know binary, there is no problem for software to perfectly handle decimal. Or fractions. Even some quite cheap calculators can handle fractions.