
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Math Floor Function in Lua Programming
There are several occurrences when we want to get the floor value of an integer to round it off and then use that value later on. The floor value of a number is the value that is rounded to the closest integer less than or equal to that integer. Lua provides us with a math.floor() function that we can use to find the floor value of a number.
Example
Let’s consider a simple example where we will make use of the math.floor() function in Lua −
a = math.floor(3.3) b = math.floor(7.1) print(a) print(b)
Output
3 7
It should be noted that if we try to find floor of a number which is already the closest integer to itself then we will get the same number as the output.
Example
Consider the example shown below −
c = math.floor(8) print(c)
Output
8
We can also pass negative numbers in the math.floor() function as an argument.
Example
Consider the example shown below −
d = math.floor(-3.3) print(d)
Output
-4
Advertisements