If you take a look at the code below you can see that I am running an if statement to check whether or not a text field is empty, if it is empty it runs the while loop. My question is when I am comparing the the two Variables, Q and Qc I only want to test the loop to a certain decimal place for example the tenths place.
I tried using @”%.1f” along with the variable but I am guessing my syntax is wrong. If someone could help me I would appreciate it.
if ([heightTextField.text isEqualToString:@""]) {
while (Q != Qc) {
Hc = Hc + 0.01;
Qc = 1.486*(Hc*W)*(powf(((Hc*W)/(2*Hc+2*W)), 0.6666666667))*(powf(S, 0.50))/n;
H = Hc;
}
}
if ([widthTextField.text isEqualToString:@""]) {
while (Q != Qc) {
Wc = Wc + 0.01;
Qc = 1.486*(H*Wc)*(powf(((H*Wc)/(2*H+2*Wc)), 0.6666666667))*(powf(S, 0.50))/n;
W = Wc;
}
}
Thanks,
Dana
There may be an easier way to go about this, but off hand, this would be the approach I would take.
First off, and this may not apply to you, but I’ve had issues comparing a textField to @”” (where it would never say this is true), so I had since used
if ([myTextField.text length])instead.As for the comparison, this is the code I would use: