# How to trunc a real?

4 messages
Open this post in threaded view
|

## How to trunc a real?

 Probably the most stupid Lua question ever asked: What's the easiest way to cut away the fractional part of a floating point number in Lua? ``` /Jon --------------------------------------------------------------------------- Jon Kleiser / ADB ekstern / USIT / University of Oslo / Norway Mail: [hidden email] / Tel: +47-22 85 28 04 / Fax: +47-22 85 29 70 --------------------------------------------------------------------------- ```
Open this post in threaded view
|

## RE: How to trunc a real?

 ```> Probably the most stupid Lua question ever asked: What's the easiest > way to cut away the fractional part of a floating point number in Lua? Since you only have one numerical type, I think the only way (besides calling a registered routine of course) is to convert the number to text format (via the format routine), and parse it. -- Lyrian ```
 ```> Since you only have one numerical type, I think the only way (besides > calling a registered routine of course) is to convert the number to text > format (via the format routine), and parse it. You can use: function int(n) if n < 0 then return ceil(n) return floor(n) end (untested, but you get the idea) -- http://sc3d.org/rrt/ | Si hoc legere scis nimium eruditionis habes. ```
 In reply to this post by Jon Kleiser ```Jon Kleiser wrote: > Probably the most stupid Lua question ever asked: What's the easiest > way to cut away the fractional part of a floating point number in Lua? ceil() or floor() will do the trick. Steve ```