What I want to do is have a timer on top of the screen counting how long you have been alive. The code for it is simple, and it works:
The problem is, it shows 7 places after the decimal. I want it to show just one so it looks like this: 70.7. I do not want it the other way as it is VERY distracting and no need for it to be so precise. I would like to know how to do this as it will help keep track of scores and what not.
answered May 16 '10 at 11:48 PM
I think this question was asked a while ago (though QATO doesn't seem to give the year with the date), but in case anyone comes across it:
To round floats to arbitrarily decimal places without converting to strings (as in Eric5h5's solution), you can use (as a general solution):
If you specifically only ever want one decimal place:
And so on...
(As an aside, you can also use this kind of technique to round to the nearest anything: e.g. to round to nearest interval of 0.3 by using