Version: 5.6
public static int RoundToInt (float f);

説明

f に最も近い整数を返します。

数が .5 で終わる場合はふたつの整数(偶数と奇数)の中間に位置していますが、偶数が返されます。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Example() { Debug.Log(Mathf.RoundToInt(10.0F)); Debug.Log(Mathf.RoundToInt(10.2F)); Debug.Log(Mathf.RoundToInt(10.7F)); Debug.Log(Mathf.RoundToInt(10.5F)); Debug.Log(Mathf.RoundToInt(11.5F)); Debug.Log(Mathf.RoundToInt(-10.0F)); Debug.Log(Mathf.RoundToInt(-10.2F)); Debug.Log(Mathf.RoundToInt(-10.7F)); Debug.Log(Mathf.RoundToInt(-10.5F)); Debug.Log(Mathf.RoundToInt(-11.5F)); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961