• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Round and convert float to integer?

skweetis

Chieftain
Joined
Mar 14, 2008
Messages
58
Location
Canada
Hey all,

Im looking for an easy way to round a decimal number to a whole number in lua , any hints?

Cheers!
 
To simply round a number you can use math.floor(x + .5). No actual "conversion" is necessary though since lua does not differentiate between integers and floats (all numbers are represented internally as doubles.)
 
awesome, thank you!

gotcha, searched through the document again and found the index with all the math and other functions listed.... can't believe I missed it...
 
it's also possible to round up, or to the closest whole number, iirc. Take a look in Lua's math standard library
 
Back
Top Bottom