NASutils Knowledge BaseUnofficialPolski

BASIC · lesson 4 of 30 · First stepsCount with numbers

The four operations, int for the whole part, mod for the remainder and str$ for a number with the decimals you choose.

Programming on the NAS › BASIC in 30 lessons

04-numbers.yab Download 04-numbers.yab

rem Four operations, the remainder and rounding
a = 17
b = 5

print "17 + 5 = ", a + b
print "17 - 5 = ", a - b
print "17 * 5 = ", a * b
print "17 / 5 = ", a / b
print "whole part: ", int(a / b)
print "remainder: ", mod(a, b)
print "17 squared: ", a ^ 2

rem print shows a fraction with six digits; str$ with a format shows
rem as many as you ask for
bytes = 1234567.891
print bytes
print str$(bytes, "%.3f")
print str$(bytes / 1024 / 1024, "%.2f"), " MiB"

Terminal

$ yabasic 04-numbers.yab
17 + 5 = 22
17 - 5 = 12
17 * 5 = 85
17 / 5 = 3.4
whole part: 3
remainder: 2
17 squared: 289
1.23457e+06
1234567.891
1.18 MiB

Exercise

Turn 500 GB into GiB and print two decimals.