|
| 04 May 2015 07:45 PM |
Hey guys so I have a script and it involves dividing and so when I divide the numbers I get a decimal and so I only want the whole number how do I do this
Example 5.32 I want to get the 5 separately from the .32 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 04 May 2015 07:52 PM |
I'm sure there are some othery methods but I like to keep it simple so you can just use a rounder.
function _G.round(val, decimal) if (decimal) then return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) else return math.floor(val+0.5) end end
print(_G.round(100.32, 0)) --This will print the number of decimals you want so,
Output: 100
print(_G.round(100.55,1)) --this will round to the first decimal place > 100.6
|
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 04 May 2015 07:54 PM |
You can use math.floor or math.modf
math.modf(2.5) --> 2, 0.5 math.floor(2.5) --> 2 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
| |
|