[英]Objective-C , Avoid negative float value to be displayed
我有以下代码:
float temp;
temp = 2.0f;
- (IBAction)MinusTouched:(id)sender {
if (temp>0.0) {
temp=temp-0.1f;
[TempValue setText:[NSString stringWithFormat:@"%.1f",temp]];
}
}
当我通过单击按钮执行操作时,温度值降低。 但是它在0.1之后显示-0.0,我如何修剪负号? 我的意思是我想要一个绝对浮点值。
在正面使用的fabs
浮点负值
[TempValue setText:[NSString stringWithFormat:@"%.1f",fabs(temp)]];
尝试使用这种方法
fabs(temp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.