How do you round numbers? Smilebasic 3
Root / Programming Questions / [.]
bluemonkey1111Created:
How do you round numbers?
Like if I had 1.4443... I would want to round it to 1.44
Or if I had 2.5542... I would want to round it to 2.55
How about rounded for calculations?
For nearest hundredth (use 100):
D=100 'Change based on amount of decimals A=1.443 'Change to whatever number you want to use A=A*D A=ROUND(A) A=A/D PRINT A '1.44As a function (in this case, D is the amount of decimal places):
DEF ROUNDD(N,D) D=POW(10,D) N=N*D N=ROUND(N) N=N/D RETURN N ENDIf you don't mind me asking, what are you planning to use this for? I can try to change this code to better fit what you're trying to do if you want.
It was just a “game” where you had to click A at exactly 2 seconds. I wanted to round the numbers because it just looks better.