Version: 2017.3

Mathf.RoundToInt

切换到手册
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