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

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
主站蜘蛛池模板: 建宁县| 长春市| 河北省| 文水县| 绥德县| 恩施市| 邯郸县| 正宁县| 柳江县| 宣城市| 霍城县| 白城市| 龙泉市| 长治县| 西昌市| 金乡县| 丰台区| 云南省| 天台县| 登封市| 东兰县| 阿瓦提县| 岳池县| 吉木萨尔县| 临泉县| 沈丘县| 高州市| 姜堰市| 肥西县| 淳安县| 肇源县| 东辽县| 新源县| 仁怀市| 大埔县| 武穴市| 龙海市| 阿拉尔市| 类乌齐县| 洪湖市| 上饶县|