多重强制转换在安卓和ios平台造成精度丢失

int a=5;

float b=a;
long c=100;

long result;

result=(long)((1+b/100)*c);
//以上代码在windows平台运算结果正确 105,但在安卓或ios平台结果为104.。。

//以下几种修改方式
result=(long)Math.Round((1f+b/100)*c);
//或者分母为float
result=(long)((1+b/100f)*c);

以上代码在unity打出的包里呈现。

猜你喜欢

转载自blog.csdn.net/l17768346260/article/details/105049469