In Unity3D, remove the entire number except the specified number of decimal places from

For text display in Unity3D. What would I do if I wanted to remove everything except the two decimal places from the float? To clarify what I want to do, see the example below:

Say I have floats:

1.25013

1,9012

1,029

Now, in Unity, what should I do if I want to reduce them, so that there are only two decimal points left, will I return 1.25, 1.90 and 1.02 before displaying the string, for example, on UI.Text?

I was looking for string formatting and stuff like Math.Floorwithout success.

+4
source share
1 answer

, , - .ToString.

, f2, , 1234.50

UI.Text = someNumber.ToString("f2");

, , , 1,234.50, n2 f2

UI.Text = someNumber.ToString("n2");
+4

Source: https://habr.com/ru/post/1649315/


All Articles