Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
| |
|
|
| 01 Jan 2015 05:52 PM |
floor,ceil =math.floor,math.ceil; roundEven =function(n) if(floor(n)%2==0) then return floor(n); else return ceil(n); end; end;
print(roundEven(2.5));
output: 2 |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Jan 2015 05:56 PM |
function round(n) return math.floor(n+.5) end |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2015 06:44 PM |
| that doesn't always work though fed. |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Jan 2015 06:47 PM |
explain why then
and i might believe you |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Jan 2015 06:48 PM |
oh btw, actual "rounding"
rounds .5 decimal up, not down. |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2015 07:11 PM |
He asked for it to round to closest even number, not just round.
take 2.5
2.5+.5=3 floor(3) = 3
3~=even |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Jan 2015 07:13 PM |
what does he mean by "even number"
i just thought he wanted to round it |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2015 07:14 PM |
| like, numbers divisible by 2. |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Jan 2015 07:15 PM |
| oh okay..in that case mine is not what he asked for at all lol |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2015 07:18 PM |
| Even numbers as in numbers that aren't odd. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 01 Jan 2015 07:29 PM |
number = math.floor((number / 2) + 0.5) * 2
Probably the simplest solution. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 01 Jan 2015 07:33 PM |
Probably.
Bankers rounding for days. |
|
|
| Report Abuse |
|
|