Objective-C从数学计算中得到0

时间:2018-06-06 21:15:02

标签: objective-c

int desiredQuality = call.arguments[@"desiredQuality"]; //BETWEEN 0 AND 1602
float calculatedQuality = desiredQuality/1602; //RETURNS 0

日志:

APP: this is the desiredQuality: 802
APP: this is the calculatedQuality: 0.000000

我尝试将calculateQuality更改为int或double,但我得到相同的结果。我做错了什么?

1 个答案:

答案 0 :(得分:1)

这是int

float calculatedQuality = desiredQuality/1602; //RETURNS 0

如果数字小于1602,它将返回0,您需要将其转换为

float calculatedQuality = desiredQuality/1602.0; //RETURNS 0.5