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!
 

MouseyPounds

Prince
Joined
Nov 8, 2010
Messages
417
Location
Maryland, USA
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.)
 

skweetis

Chieftain
Joined
Mar 14, 2008
Messages
58
Location
Canada
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...
 

Gangor

King
Joined
Jan 21, 2002
Messages
825
Location
Berks, UK
it's also possible to round up, or to the closest whole number, iirc. Take a look in Lua's math standard library
 
Top Bottom