Created
May 14, 2020 13:39
-
-
Save todorok1/baae9fefe724aa64a1667aaab5624eea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <Summary> | |
/// 数値を足す場合と目標となる数値そのものを近似的に比較した場合で同じになるか確認するメソッドです。 | |
/// 値はメソッド内で直接指定します。 | |
/// </Summary> | |
void CompareAddedValueToTargetApproximately() | |
{ | |
// 値を変数にセットします。 | |
float valueA = 0.1f; | |
// 値を10回足します。 | |
float added = 0; | |
for (int i = 1; i <= 10; i++) | |
{ | |
added += valueA; | |
} | |
// 目標となる値をセットします。 | |
float targetValue = 1.0f; | |
// 足した場合とそのままの場合が同じか確認します。 | |
string resultText = ""; | |
if (Mathf.Approximately(added, targetValue)) | |
{ | |
resultText = "同じです。"; | |
} | |
else | |
{ | |
resultText = "異なっています。"; | |
} | |
Debug.Log($"足した値 {added} と目標の値 {targetValue} は {resultText}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment