Reading — step 1 of 5
Learn
~1 min readFirst Steps
Standard arithmetic: + - * /. Integer division: // (Lua 5.3+). Modulo: %. Exponent: ^.
print(7 / 2) -- 3.5 (always float division)
print(7 // 2) -- 3 (floor division)
print(7 % 2) -- 1
print(2 ^ 10) -- 1024.0
Math functions live in the math library:
print(math.floor(3.7)) -- 3
print(math.sqrt(16)) -- 4.0
print(math.max(1, 9, 4)) -- 9
print(math.pi) -- 3.1415926535898
Convert string to number with tonumber(s). Returns nil if not parseable.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…