unity将小数点精确到小数点后一位

在 Unity 中,可以使用 Mathf.Round() 函数来将小数点精确到小数点后一位。例如:

float num= 3.14159265f;
float roundedNum = Mathf.Round(num * 10f) / 10f;

在上面的代码中,我们将 num 乘以 10,然后使用 Mathf.Round() 函数对其进行四舍五入。最后,再将结果除以 10,得到精确到小数点后一位的数字。

猜你喜欢

转载自blog.csdn.net/weixin_35752233/article/details/129060247