- Lua Quick Start Guide
- Gabor Szauer
- 168字
- 2021-08-05 10:30:37
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
推薦閱讀
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- Power Up Your PowToon Studio Project
- Web Scraping with Python
- JavaFX Essentials
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 名師講壇:Java微服務架構實戰(SpringBoot+SpringCloud+Docker+RabbitMQ)
- EPLAN實戰設計
- Swift語言實戰精講
- Node.js全程實例
- C/C++程序員面試指南
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- 深度學習:Java語言實現
- Android項目實戰:手機安全衛士開發案例解析
- C/C++數據結構與算法速學速用大辭典
- Web開發的平民英雄:PHP+MySQL