double a = 10.123420834;
double b = 100.123412321;
if (a > b) {
// do something here
}
I am trying to compare the two values,开发者_如何学C the code above doesn't seems to work. Any idea?
The code is correct.
Note that your snippet is equivalent to
float a = 10.123420834;
float b = 100.123412321;
if (a > b) {
// do something here
}
since Objective C uses double
by default unless the number is followed by an f
.
Also note that a < b
, so the if
statement will always evaluate to FALSE
. Hence you may want to do
double a = 10.123420834;
double b = 100.123412321;
if (a > b) {
// do something here
} else {
// do something else here
}
to test this properly.
double a = 10.123420834
double b = 100.123412321
You need to have a semicolon at the end of each of those lines.
The code in your example is correct. Your problem must be in the "do something here", or elsewhere.
精彩评论