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

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
主站蜘蛛池模板: 尼勒克县| 叶城县| 金沙县| 奉贤区| 沈丘县| 砚山县| 新绛县| 临清市| 云霄县| 安吉县| 修水县| 阳泉市| 冀州市| 深泽县| 周至县| 宁阳县| 阿尔山市| 孟村| 潼南县| 新昌县| 山阳县| 宣城市| 盘锦市| 堆龙德庆县| 崇左市| 通州区| 新和县| 股票| 修水县| 长葛市| 叙永县| 岳池县| 兴仁县| 阳西县| 石棉县| 米脂县| 临夏县| 榆社县| 中西区| 儋州市| 庆元县|