Rounding Decimals
Moderators: Shine, Insert_witty_name
-
- Posts: 35
- Joined: Mon Aug 22, 2005 7:48 am
Rounding Decimals
Can anyone tell me how to round down or round up a decimal number?
Programming in Lua
rounding functions (floor, ceil)
Wikipedia entry for floor and ceil
floor: for a real number x, floor(x) is the largest integer less than or equal to x.
ceil: for a real number x, ceiling(x) is the smallest integer no less than x.
rounding functions (floor, ceil)
Wikipedia entry for floor and ceil
floor: for a real number x, floor(x) is the largest integer less than or equal to x.
ceil: for a real number x, ceiling(x) is the smallest integer no less than x.
-
- Posts: 35
- Joined: Mon Aug 22, 2005 7:48 am
try that.
x = 8.13
math.round(x) = 8
y = 8.52
math.round(y) = 9
Code: Select all
function math.round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
math.round(x) = 8
y = 8.52
math.round(y) = 9
Puzzle Bobble - The arcade port!