...
float f = 2.556468f;
int i_1 = (int)f;
float f_1 = f-i_1;
...
...
void Start()
{
float f1 = 20.5641f;
int i = 0;
float f2 = 0;
test(f1,out i,out f2);
Debug.Log("f1:"+f1+"/i:"+i+"/f2:"+f2);//f1:20.5641/i:20/f2:0.5641003
}
...
void test(float f,out int i,out float f1)
{
i = (int)f;
f1 = f - i;
}
...
double,long等类型 与上相同。

这篇博客探讨了C#中如何将浮点数转换为整数,并计算浮点数与整数之间的余数值。示例代码展示了如何使用(int)强制类型转换以及如何在函数中传递参数进行此类运算。通过`test`函数,可以看到浮点数20.5641在转换为整数20后,余数值为0.5641003。
27

被折叠的 条评论
为什么被折叠?



