- 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
推薦閱讀
- Mastering JavaScript Functional Programming
- R語言數據分析從入門到精通
- Android項目開發入門教程
- Python語言程序設計
- Python從菜鳥到高手(第2版)
- Functional Kotlin
- Android 應用案例開發大全(第3版)
- RubyMotion iOS Develoment Essentials
- 零基礎學C語言(第4版)
- Delphi開發典型模塊大全(修訂版)
- 奔跑吧 Linux內核
- Elasticsearch搜索引擎構建入門與實戰
- 絕密原型檔案:看看專業產品經理的原型是什么樣
- 基于Docker的Redis入門與實戰
- AngularJS Web Application Development Cookbook