|
| 18 Sep 2016 11:09 AM |
| I have a script that tells you the current progress in percent that you've done in the obstacle course, it works, but I get numbers like 8.33333333333, is there a way to round these to 8? |
|
|
| Report Abuse |
|
|
Intern33t
|
  |
| Joined: 19 Nov 2010 |
| Total Posts: 1530 |
|
|
| 18 Sep 2016 11:20 AM |
simple:
math.floor(8.3333333)
hard:
in 8.x, if x >=5 then math.ceil(8.x) else math.floor(8.x) |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
| |
|
Intern33t
|
  |
| Joined: 19 Nov 2010 |
| Total Posts: 1530 |
|
|
| 18 Sep 2016 11:32 AM |
rounding 8.1 with your method would yield 8.5, so would 8, but 7.9 would 7.5
very inefficient and misleading |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2016 11:35 AM |
| No it wouldn't it would work better he wants it to round not to floor with math.floor(x+0.5) lets say the number is 7.1- 7.4 it would round to 7 but if the number is 7.5-8.4 it would round to 8 |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 18 Sep 2016 11:59 AM |
it rounds to the nearest integer
8.1 -> 8.6 -> 8 8.5 -> 9 -> 9 7.9 -> 8.4 -> 8
|
|
|
| Report Abuse |
|
|
|
| 18 Sep 2016 12:34 PM |
math.floor rounds to the nearest low integer*
math.floor(8) > 8 math.floor(8.5) > 8 math.floor(8.9) > 8 math.floor(9) > 9
math.ceil(8) > 8 math.ceil(8.5) > 9 math.ceil(8.9) > 9 math.ceil(9) > 9
you add 0.5 so that it does this
math.floor(8.7 + 0.5) > 9 (8.7 + 0.5 = 9.2)
to round to a higher number, you do very simple math so that you increase the number so that all of your decimal places will lie inside of the integer
math.floor(num*10+0.5)/10
and to change the amount of places you can use, simply use scientific notation
math.floor(num*(10^Places) + 0.5)/(10^Places) |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2016 12:35 PM |
| to round to a number and maintain decimals* |
|
|
| Report Abuse |
|
|