Comments and answers for "Raycast // Accuracy math pls help"
http://answers.unity.com/questions/1841480/raycast-accuracy-math-pls-help.html
The latest comments and answers for the question "Raycast // Accuracy math pls help"Comment by unity_ek98vnTRplGj8Q on unity_ek98vnTRplGj8Q's comment
http://answers.unity.com/comments/1841493/view.html
You can use a string format to just get the number to display to the tenth's place
acc.text = "Accuracy: " + string.Format("{0:0.#}", acurracy) + "%";
You can change the formatting to show as many or as few decimal places as you wantWed, 09 Jun 2021 20:55:01 GMTunity_ek98vnTRplGj8QComment by Xision on Xision's answer
http://answers.unity.com/comments/1841491/view.html
Awesome! Thanks so much, so im now running into an issue where it will only show the percentage as long as there's no repeating decimal. Is there a way to force the code to round to the nearest tenth? Or whole number even?Wed, 09 Jun 2021 20:38:59 GMTXisionAnswer by unity_ek98vnTRplGj8Q
http://answers.unity.com/answers/1841484/view.html
All of your variables are integers, meaning they always have to be a whole number. Your accuracy should be a float, and your other values need to be cast as a float as you are doing math.
float accuracy;
int shotsFired, shotsHit;
accuracy = ((float)shotsHit / (float)shotsFired) * 100f;Wed, 09 Jun 2021 20:13:28 GMTunity_ek98vnTRplGj8Q