Version: 5.4 (switch to 5.5b)
言語English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mathf.Approximately

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

マニュアルに切り替える
public static function Approximately(a: float, b: float): bool;
public static bool Approximately(float a, float b);

Parameters

Description

類似している 2 つの Float 型の値を比較します

float が持つ誤差から等値演算子 (=) を使用して float 同士を比較することはお勧めしません。 例えば、 1.0 == 10.0 / 10.0 の結果は true を返さない場合があります。

if (Mathf.Approximately(1.0, 10.0/10.0))
    print ("same");
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Example() { if (Mathf.Approximately(1.0F, 10.0F / 10.0F)) print("same"); } }