LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

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

Do you want to round it to use it in more calculations? Or do you just want to round it so you can display it? If you just want to display it rounded, you can do this:
PRINT FORMAT$("%.2F", 1.4443)
The number after . in %.2F is how many digits after the decimal point you want.

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.44
As 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
END
If 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.