Hello,
I have float variables like 4.101814. How can I reduce its lenght to 2, so it would look like this: 4.10
Thanks!
Hello,
I have float variables like 4.101814. How can I reduce its lenght to 2, so it would look like this: 4.10
Thanks!
float val = 4.101814f;
float roundedVal = 0.01f * Mathf.Round(100.0f * val);
If you want to display the float as string you should use a custom format string.
In your case
// C#
float val = 4.101814f;
Debuf.Log("The value is "+val.ToString("0.00"));
// prints: "The value is 4.10"
// UnityScript
var val = 4.101814f;
Debuf.Log("The value is "+val.ToString("0.00"));
// prints: "The value is 4.10"