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