• 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

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

  • 相关阅读:
    android外存文件读写
    android内存文件读写
    SearchView的使用
    Notification的使用(待完善)-〉添加点击取消,显示优化
    列表Dialog和“确认”、“取消”Dialog
    PopupWindow弹出窗口的使用
    侧拉菜单
    腾讯分析移动设备屏幕分辨率分析报告--转
    git hub使用
    input 原始版,后面修改
  • 原文地址:https://www.cnblogs.com/ChenZiRong1999/p/13383705.html
Copyright © 2020-2023  润新知