static function Approximately (a : float, b : float) : bool
Description描述
Compares two floating point values if they are similar.
比较两个浮点数值,看它们是否非常接近。
Due to floating point imprecision it is not recommended to compare floats using the equal operator. eg. 1.0 == 10.0 / 10.0 might not return true.
由于浮点数值不精确,不建议使用等于来比较它们。例如,1.0==10.0/10.0也许不会返回true。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
if (Mathf.Approximately(1.0F, 10.0F / 10.0F))
print("same");
}
}
if (Mathf.Approximately(1.0, 10.0/10.0))
print ("same");