官术网_书友最值得收藏!

number

Lua does not know the difference between a whole number and a decimal. All numbers are simply real numbers. Sometimes, especially when working with grids, you might need only whole numbers. If that is the case, Lua has a built-in function to round down, math.floor, or to round up, math.ceil. This is how they can be used:

pi = 3.1415
three = math.floor(3.1415)
five = math.ceil(4.145)
print (pi) -- will print: 3.1415
print (three) -- will print: 3
print (five) -- will print: 5
Using functions might look foreign right now, but don't worry, they will be covered in detail later in the chapter.

Basic arithmetic operations such as adding, subtracting, multiplying, or dividing can be performed on integers. We will cover arithmetic operations in detail later on in the chapter, but for now, let's take a look at something simple, adding two numbers:

five = 3 + 2
print (five) -- will print 5
print (2 + 2) -- will print 4
print (five + 1) -- will print 6
主站蜘蛛池模板: 古田县| 乌拉特中旗| 承德市| 江阴市| 宿迁市| 和平县| 巴林右旗| 保山市| 寻乌县| 拉萨市| 汨罗市| 宜宾县| 台南市| 山东省| 临泽县| 嘉善县| 孟津县| 芷江| 葵青区| 新郑市| 天等县| 普宁市| 巴塘县| 黔西县| 南华县| 宁城县| 河津市| 东源县| 南宫市| 高平市| 浪卡子县| 永吉县| 曲麻莱县| 海丰县| 海阳市| 勃利县| 沿河| 虞城县| 沧州市| 兴安县| 大连市|