You can use the formatting options with .ToString: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
#How to have my speedometers math round up to the nearest whole.
1 messages · Page 1 of 1 (latest)
Thank you so much!
That is going to the favorites bar.
Lets see if this works nowl.
Not seeing anything that would do the math to round up removing the left over decimals.
found a much better solution which gives a very accurate calculation for what the speed is actually like.
playerUISpeed = (int)Mathf.Round(playerSpeed * 2.2369362921f);
speedLabel.text = (playerUISpeed + "MPH");
There is the code.
Any final opinions on my code? I found the solution by tracking through some references in the link you provided.
Round is a good option, if you want to control how a 0.5 or midpoint is handled, you could also use Floor to round down or Ceil to round up, and if you wanted to remove a cast, if its something you plan to call often, you could maybe use the Convert class - you can also find all that on the MSDN site, .ToString is meant for displaying your final number if it shows more decimals than youd like to see, but it might not round (may have initially misunderstood your question, glad it helped though)