- Home /
Turn float to int
I multiplied a float with Time.deltaTime like: SomeFloat -= 0.001 * Time.deltaTime And i'm showing the "SomeFloat" float graphicaly with GUI.Label, and it works like it's supposed to, reduces by -0.001 every second... I'm actually making a precent, like how much % is left of "SomeFloat" in the GUI.Label, It's good, but it's like 99.999 %, 99.998 %, 9.997 .... 0.001 % But i want it to display it as an classic 2 or 1 spaces long number (Like 99.998 % shows like 99%) So i never worked with ints, using C#, but my guess is that int doesen't show dots, just full numbers... SOOO, i guess i need to show float as an int ? Or is there some other solution ? I don't know anymore, this is probabbly confusing, i couldn't explain better, i'm sorry.
Answer by Kiwasi · Oct 09, 2014 at 05:39 PM
ToString is what you want. Try this answer out.
http://answers.unity3d.com/questions/12981/seperate-large-numbers-with-comma.html
Found a way before i read this answer, but thank you for your time anyway
Answer by RickyX · Oct 09, 2014 at 07:29 PM
I came up to an answer by searching, i just made a new int, and said it's = to (int)Somefloat, which turns somefloat to an int
Just be aware that casting to an int will require some more work if you want to add commas, or a couple of decimal points.
Thanks for this, I had the same question and this totally helped
Your answer
Follow this Question
Related Questions
Cannot convert 'callable(int) as float' to 'float'. 1 Answer
Possible to convert a Float into an Int? 3 Answers
Javascript int to float 1 Answer
GUI.Label shows volume from a slider 3 Answers