wri*_*lih 4 c# unity-game-engine
我想知道除法后我得到的是整数还是浮点数。
if (5.4 / 0.8 ==integer) // except something that would evaluate as true in this case
{
}
Run Code Online (Sandbox Code Playgroud)
一种方法是使用Mathf.Round找到最接近结果的Mathf.Approximately整数并将该整数与结果进行比较:
float f1 = 0.5;
float f2 = 0.1;
float result = f1/f2;
if (Mathf.Approximately(result, Mathf.Round(result)) {
Debug.Log("integer result");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
719 次 |
| 最近记录: |