Why the following condition is never met?
C#
3
Posts
2
Posters
0
Views
1
Watching
-
double number1 = 1, number2 = .5; while (number1 > number2) { number1 -= .1; MessageBox.Show(number1.ToString()); if (number1 == number2) MessageBox.Show("condition met"); // <- never :( } Please help
Floats are not guaranteed to be perfectly accurate because of the way they're stored. What are the numbers you get in your message box as it goes down? You may want to give
Decimal
a try.
-
Floats are not guaranteed to be perfectly accurate because of the way they're stored. What are the numbers you get in your message box as it goes down? You may want to give
Decimal
a try.