Floating point iterations fail

Iteration works with integers but fails with floating numbers.
I recently wrote code for an iteration to decrement a number something like this:

While (number) is less than (end number)
number = number - (number to subtract)
If (number) = (expected number)
print True
print false

If I start with 10 and subtract 1 until I get to 1 it works fine, however,
I I start with 1 and subtract .1 until I get to .1 it fails.

Why not show your relevant blocks and screen output?

Where is the variable expectedNumber coming from ?

How do I do that?

If I iterate down to a certain number number then I expect that number.
integers work, floating point doesn't.

You have stumbled upon a feature of floating point numbers.
Decimal 1/10 is an unending decimal fraction in binary floating point,
like 1/3 is unending in decimal representation.

There is no exact floating point representation of .1 iin AI2.

If you must deal in decimal fractions, use the math block that formats them as decimal text.

Well I tried that but it still doesn't work
If I set variable to decimal 1 then do a while loop subtracting decimal 0.1 while > decimal 0.1
then I get 1.3878E-16

I will try the format block and see what happens.

Finally figured it out. Thanks

please provide the solution to your problem...
your question and answers are not only for you, but also for others which might have the same question in future
thank you


When decrementing a decimal number in a while loop, the result comes back with random numbers 16 decimal places out. to fix the result I had to put a "format as decimal number" block in the equation to round off the random numbers as shown.