0

我试图找到将浮点值放入UIAlertView. 我的float值仅用于检查另一个值,而不是传递给某处的字符串。

我想我可以将我的float值设置为标签并将其设置为hidden并将其传递给我的警报,但我确定这不是正确的方法,我们将不胜感激

float x = ([_continuityRingFinalR1.text floatValue]); /stringWithFormat:@"%.1f", x * y]]
float y = (1.67);

if ([_continuityRingFinalRn.text floatValue] > x * y ) {


         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Advisory Warning"
         message:[NSString stringWithFormat: @"Based on your value of %@  this value may not be acceptable. %@ would be acceptable",_continuityRingFinalR1.text, ]///<<< my float value here
         delegate:self cancelButtonTitle: @"Ignore" otherButtonTitles: @"Retest", nil];



    [alert show];
}
4

2 回答 2

2

%f在 NSString 中用于浮点/双精度而不是 %@

    float x = ([_continuityRingFinalR1.text floatValue]); /stringWithFormat:@"%.1f", x * y]]
    float y = (1.67);
    float example;

    if ([_continuityRingFinalRn.text floatValue] > x * y ) {

             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Advisory Warning"
             message:[NSString stringWithFormat: @"Based on your value of %@  this value may not be acceptable. %f would be acceptable",_continuityRingFinalR1.text, example];
             delegate:self cancelButtonTitle: @"Ignore" otherButtonTitles: @"Retest", nil];

        [alert show];
    }

这是一个有用的链接

于 2013-01-13T11:31:47.447 回答
1

我想你想要这个

message:[NSString stringWithFormat: @"Based on your value of %@  this value may not be acceptable. %0.2f would be acceptable",_continuityRingFinalR1.text, x*y ];
//Passing second argument as x*y
于 2013-01-13T11:24:11.180 回答