|
I have the following statement in my code, it displays a percentage value calculated. the value currently has about 10 decimal places coming up but i dont want any, how can i adapt this code so that it doesn't show any decimal places? GUI.Label(new Rect(0, 100, 50, 50), System.Convert.ToString(Calculate(ace)) + "%");
(comments are locked)
|
|
What is the value of ace, and what does Calculate do? Assuming that the result is just a long decimal or float, try this... GUI.Label(new Rect(0, 100, 50, 50), System.Convert.ToString(Mathf.Round(Calculate(ace))) + "%"); or GUI.Label(new Rect(0, 100, 50, 50), System.Convert.ToString(Mathf.Floor(Calculate(ace))) + "%"); to just truncate the decimals Hope this helps, -Larry LOL Once again I take too long to respond, and someone beats me to it ;)
Jan 11 '12 at 05:29 PM
Larry Dietz
I need the rep :) nearly at 1k!
Jan 11 '12 at 05:34 PM
Muzz5
(comments are locked)
|
|
thanks for trying dude! calculate is a method which calculates the percentage of the variable ace which can change all the time. turns out whole number is making the % less accurate though is there a way to keep it down to just 1 or 2 decimal places? It just truncate the value to a couple of decimal places, you cn do something like this... GUI.Label(new Rect(0, 100, 50, 50), System.Convert.ToString(Calculate(ace).Substring (0, System.Convert.ToString(Calculate(ace)).IndexOf (".")+3 ) + "%"); Or better yet, store the return of Calculate(ace) in a string variable, and use that variable in the GUI.Label to avoid calling Calculate 2 times. I beleive that should work. -Larry
Jan 11 '12 at 05:45 PM
Larry Dietz
i have saved the string as total in the other method. how would i transform it into your code?
Jan 11 '12 at 05:53 PM
Chris 31
Try... string Total = System.Convert.ToString(Calculate(ace)) GUI.Label(new Rect(0, 100, 50, 50), Total.Substring(0, Total.IndexOf (".")+3 ) + "%"); This is off the top of my head. Havent actually tried it in Unity, but beleive it should work. -Larry
Jan 11 '12 at 06:02 PM
Larry Dietz
ah thanks man :)
Jan 11 '12 at 06:13 PM
Chris 31
(comments are locked)
|
