When dealing with numerical values and returning scores, etc. you may notice that sometimes values are returned with extraneous decimal values, such as 456.000000000002. This is great for accuracy, but not so great when you want to return values to the player, such as scores, damage per second, and so on. Too many decimal places are generally unneeded, are annoying to the player, and will likely mess up your screen (i.e. stretching across the entire screen and even passing beyond.), Fortunately it’s easy to deal with.
Unwanted decimal places are easily dealt with, and you can also choose how many decimal places you wish to show.
The above code isn’t particularly complicated, though there’s a few things you need to know. First of all, ‘Your Value’ is the value you wish to display, yet limit the number of decimal places.
Secondly you’ll see the number 10 mentioned twice. This converts the number into the required number of decimal places. Think of each ‘0’ as a decimal place; so if our value is one, ’10’ will return 1.0, ‘100’ will return 1.00, as so on.