【问题标题】:How to write a condition for float value?如何为浮点值编写条件?
【发布时间】:2011-07-02 13:34:32
【问题描述】:

您好,我正在使用 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,那么应该只显示温度值。条件是什么?

【问题讨论】:

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


    【解决方案1】:

    使用

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

    代替

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

    【讨论】:

    • 在第一个 if 循环中检查 temp1 是否等于 0.00,在第二个循环中首先将 temp1 分配给 0.00 然后检查 if(temp1),即如果 temp1 > 0.00 则为真
    • 我找不到上面两个有什么变化
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 2022-01-09
    • 2011-04-19
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    相关资源
    最近更新 更多