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

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
主站蜘蛛池模板: 宁都县| 洛阳市| 岑溪市| 元阳县| 海原县| 桃园市| 江口县| 即墨市| 潞城市| 得荣县| 佛山市| 青冈县| 叶城县| 怀化市| 汉阴县| 吴堡县| 凤城市| 芒康县| 定襄县| 天峨县| 杭锦后旗| 定边县| 奈曼旗| 淮阳县| 读书| 青田县| 武胜县| 轮台县| 台南市| 江油市| 山东| 曲沃县| 富裕县| 蚌埠市| 肥西县| 泰宁县| 邓州市| 滨州市| 阳西县| 宣恩县| 江都市|