- Home /
Question by
Detinator10 · Aug 13, 2014 at 02:05 AM ·
floatdecimal
how to limit how far a float goes back
I am keeping track of time using a float in my game and I then show it in the corner of the screen. I don't want it to go out the full, however many, digits behind the decimal point. I just want it to go back two numbers after the decimal point. So how would I do that? Thank you!
Comment
Best Answer
Answer by aman_jha · Aug 13, 2014 at 02:15 AM
If it's just for changing to string:
yourFloat.ToString("F2")
If you want the float itself truncated:
yourFloat = Mathf.Round(yourFloat * 100f) / 100f;
thank you! the yourfloat.Tostring("F2") didn't work for me but the second one did.
Your answer
Follow this Question
Related Questions
I dont want Decimals :P 1 Answer
What is the max float? -1 Answers
Javascript rounding off a decimal 0 Answers
How to limit the amount of decimals with a slider in Unity Editor OnInspectorGUI? 1 Answer
print to only two decimal places. 2 Answers