如何写浮点值的条件?

时间:2011-02-23 07:28:35

标签: iphone-sdk-3.0 ios4 ios-simulator

我正在使用sqlite。  stringFloat1 = [pediDetails.doseTo FloatValue];

float mulWith1 = [appDelegate.selectedWeight FloatValue];

NSLog(@"mulwith1:%f",mulWith1);
//if(mulWith1 =0.00) {
//  int temp1=0;
//}
//  else {

float temp1 = stringFloat1*mulWith1;
NSString *setWeight;
NSLog(@"temp1:%f",temp1);
//  }
//float temp1;
//NSString *setWeight = [NSString stringWithFormat:@"%.02f",temp,temp1];

//if(temp1=0.00) {
//setWeight = [NSString stringWithFormat:@"%.02f",temp];
//}
//else{ 
setWeight = [NSString stringWithFormat:@"%.02f-%.02f",temp,temp1];

我需要的是,如果temp1为0.00,则只显示临时值。条件是什么?

1 个答案:

答案 0 :(得分:1)

使用

if(temp1==0.00)
{
   setWeight = [NSString stringWithFormat:@"%.02f",temp];
}

而不是

if(temp1=0.00)
{
  setWeight = [NSString stringWithFormat:@"%.02f",temp];
}