blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 11 Sep 2011 08:14 AM |
I have a decimal such as 4.8384737 How can I round it to 4.8 in Lua?
~A revolution is born when one forgets the meaning of "impossible" |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 11 Sep 2011 08:17 AM |
decimal = 4.8384737 * 10 round = math.ceil(decimal) round = round / 10 print(round)
>4.8
Maybe?
~A revolution is born when one forgets the meaning of "impossible" |
|
|
| Report Abuse |
|
|
sycips
|
  |
| Joined: 21 Mar 2011 |
| Total Posts: 1368 |
|
|
| 11 Sep 2011 08:20 AM |
you can do that with this:
you number is like 9.6478325.
string.format(%.1f, 9.6478325)
output will be: 9.6! try for yourself.
%.1f means 1 decimal %.2f means 2 decimal %.3f means 3 decimal ect.
ok? |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2011 08:39 AM |
| Any of you ever heard of math.floor()? |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 11 Sep 2011 08:42 AM |
@RATE math.ceil rounds up, and math.floor rounds down.
~A revolution is born when one forgets the meaning of "impossible" |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2011 08:43 AM |
| I know and in your case you use math.floor |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 11 Sep 2011 08:44 AM |
It doesn't much matter.
~A revolution is born when one forgets the meaning of "impossible" |
|
|
| Report Abuse |
|
|
sycips
|
  |
| Joined: 21 Mar 2011 |
| Total Posts: 1368 |
|
| |
|
sycips
|
  |
| Joined: 21 Mar 2011 |
| Total Posts: 1368 |
|
|
| 11 Sep 2011 08:55 AM |
| btw math.ceil and math.floor rounds with zero decimals string.format will round in decimals... |
|
|
| Report Abuse |
|
|
sycips
|
  |
| Joined: 21 Mar 2011 |
| Total Posts: 1368 |
|
|
| 11 Sep 2011 09:00 AM |
| srry again because string.format was something I didn't read at the roblox wiki and it doesn't work on roblox -_-" so srry can't help you... |
|
|
| Report Abuse |
|
|