Skip to content

Instantly share code, notes, and snippets.

@todorok1
Last active July 3, 2018 09:18
Show Gist options
  • Save todorok1/d3368c22df93b4d53d1aebd26d84f7ff to your computer and use it in GitHub Desktop.
Save todorok1/d3368c22df93b4d53d1aebd26d84f7ff to your computer and use it in GitHub Desktop.
MathfのRoundを使った時の動作
void RoundTest(){
float value = 3.15f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
Debug.Log("value : " + value + " / RoundToInt : " + Mathf.RoundToInt(value));
value = -9.61f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
Debug.Log("value : " + value + " / RoundToInt : " + Mathf.RoundToInt(value));
value = 2.51f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
value = 3.5f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
value = 4.5f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
value = 5.5f;
Debug.Log("value : " + value + " / Round : " + Mathf.Round(value));
float roundedValue = Mathf.Round(value);
// 明示的にキャストが必要
int roundedIntValue = (int) Mathf.Round(value);
float roundedToIntValueToFloat = Mathf.RoundToInt(value);
int roundedToIntValueToInt = Mathf.RoundToInt(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment