zoukankan      html  css  js  c++  java
  • Unity Mathf/Math 数学运算函数

    一、Mathf.Round  四舍五入

     四舍五入取最接近的整数,返回值是 float 类型

     如果数字的末尾是 .5,不管是偶数还是奇数,将返回偶数

    例如:

    1    Debug.Log(Mathf.Round(10.0f));
    2    Debug.Log(Mathf.Round(10.2f));
    3    Debug.Log(Mathf.Round(10.7f));
    4    Debug.Log(Mathf.Round(10.5f));
    5    Debug.Log(Mathf.Round(11.5f));

     由于末尾是 0.5,所以返回偶数

     而 11 不是偶数,所以分别返回 10 和12

    二、Mathf.RoundToInt  四舍五入

     四舍五入取最接近的整数,返回值是 Int 类型整数

     如果数字末尾是 .5,不管是偶数还是奇数,将返回偶数

    例如:

    1    Debug.Log(Mathf.RoundToInt(10.0f));
    2    Debug.Log(Mathf.RoundToInt(10.2f));
    3    Debug.Log(Mathf.RoundToInt(10.7f));
    4    Debug.Log(Mathf.RoundToInt(10.5f));
    5    Debug.Log(Mathf.RoundToInt(11.5f));

     由于末尾是 0.5,所以返回偶数

     而 11 不是偶数,所以分别返回 10 和12

    三、Mathf.Ceil  向上限值取整

     向上限值取整,返回值是 float 类型

     如果是负数 -8.8,由于取上原则,则取 -8

    例如:

    1    Debug.Log(Mathf.Ceil(8)); 
    2    Debug.Log(Mathf.Ceil(8.1f));
    3    Debug.Log(Mathf.Ceil(8.5f));
    4    Debug.Log(Mathf.Ceil(8.8f));
    5    Debug.Log(Mathf.Ceil(-8.5f));
    6    Debug.Log(Mathf.Ceil(-8.9f));

    四、Mathf.Floor  向下限值取整

     向下限值取整,返回值是 float 类型

     如果是负数 -8.8,由于取下原则,则取 -9

    例如:

    1    Debug.Log(Mathf.Floor(8));
    2    Debug.Log(Mathf.Floor(8.1f)); 
    3    Debug.Log(Mathf.Floor(8.5f)); 
    4    Debug.Log(Mathf.Floor(8.8f)); 
    5    Debug.Log(Mathf.Floor(-8.5f)); 
    6    Debug.Log(Mathf.Floor(-8.9f));

    原文:https://blog.csdn.net/ChinarCSDN/article/details/81284727

    *** |  以上内容仅为学习参考、学习笔记使用  | ***

  • 相关阅读:
    C# 中的类型转换
    Structured Query Language 入门 oracle
    C# 模板代碼的總結
    .net 頁面通過C#控件綁定時間格式的方法
    醫務室系統報表中使用的一個使用遊標的自定義方法 sqlserver
    vi 编译器的退出
    和为s的数字
    两个链表的第一个公共节点
    某数字在排序数组中出现的次数
    二叉搜索树的第k个节点
  • 原文地址:https://www.cnblogs.com/ChenZiRong1999/p/13383705.html
Copyright © 2011-2022 走看看