1. 【 Mathf.Ceil】 向上进位取整
int allCount = 1;
float result = (float)allCount/3f; // 0.33333
float height = Mathf.Ceil(result);// 1
2.【 Mathf.RoundToInt】四舍五入到整数
private void Test()
{
float str1 = 7.66f;
float str2 = 7.46f;
float str3 = 7.56f;
Debug.Log (str1.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str1).ToString());// 8
Debug.Log (str2.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str2).ToString());// 7
Debug.Log (str3.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str3).ToString());// 8
}
3.【
Mathf.Round】
四舍五入
private void Test()
{
float str1 = 7.66f;
float str2 = 7.46f;
float str3 = 7.56f;
Debug.Log (str1.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str1).ToString());// 8
Debug.Log (str2.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str2).ToString());// 7
Debug.Log (str3.ToString()+":四舍五入到整数 ="+Mathf.RoundToInt(str3).ToString());// 8
}
4.【
Mathf.Abs】绝对值
private void Test()
{
float str1 = -10f;
float str2 = 10f;
Debug.Log (str1.ToString()+":绝对值 ="+Mathf.Abs(str1).ToString());// 10
Debug.Log (str1.ToString()+":绝对值 ="+Mathf.Abs(str2).ToString());// 10
}