- 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
推薦閱讀
- Designing Machine Learning Systems with Python
- 一步一步學(xué)Spring Boot 2:微服務(wù)項目實戰(zhàn)
- WildFly:New Features
- Java程序設(shè)計(慕課版)
- Mastering Selenium WebDriver
- PHP+MySQL網(wǎng)站開發(fā)技術(shù)項目式教程(第2版)
- Java設(shè)計模式及實踐
- Symfony2 Essentials
- 劍指Java:核心原理與應(yīng)用實踐
- Visual C#通用范例開發(fā)金典
- RabbitMQ Essentials
- 深入解析Java編譯器:源碼剖析與實例詳解
- Shopify Application Development
- HikariCP數(shù)據(jù)庫連接池實戰(zhàn)
- Node.js Web Development