EditorGUI.FloatField - How to round decimal places?

I want to limit the display in my EditorGUILayout.FloatField to 2 decimal places. Is there a way to do this?

Thanks

1 Answer

1

There are a few suggestions in this other UA thread.

If you’re going to do this a lot, there are pretty good ways; if it’s more of a one-off thing, you could always convert float → string with X digits → rounded float.

float f = ... //some float
f = float.Parse(f.ToString("F2"));

Thanks rutter, the last line is perfect for my use as I can use it directly in FloatField() without having to declare a separate float.