|
| 11 May 2013 08:36 PM |
| Is there any way to round a number? I'm having issues with very slightly larger numbers printing with a ridiculous number of digits. It's quite frustrating to read and differentiate, though I don't need to get rid of them. |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 08:36 PM |
math.floor(0.11) --rounds down to the nearest math.ceil(0.11) --rounds up to the nearest |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 08:47 PM |
| What if the numbers I'm looking for don't round to whole numbers? Is there nothing for that? |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 May 2013 08:58 PM |
| I'm afraid I don't follow. A string is a whole different concept from everything I know. |
|
|
| Report Abuse |
|
|
Aerideyn
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 1882 |
|
|
| 11 May 2013 08:59 PM |
then move the decimal point , floor it, then move it back.
function round(number,decimalPoints) return math.floor(number*10^decimalPoints)+0.5 end |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 09:02 PM |
| I figure I could do this with basic math, then. Keep it true to what it is, or some other philosophical malarkey that doesn't really apply. |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 09:04 PM |
| Actually, I completely missed what I was asking the second time, thinking about it. I can't just round it to the low or high section, some of the numbers are slightly lower while others are slightly higher. That would set it off by nearly a full stud (or tenth of a stud in this case). |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 09:09 PM |
@Aeridyn
Good try, but not quite there.
return math.floor(number*10^decimalPoint+0.5)/10^decimalPoint
You forgot to move and back and implement the 0.5 inside the method. |
|
|
| Report Abuse |
|
|
Aerideyn
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 1882 |
|
|
| 12 May 2013 01:50 AM |
oh yes of course :o That is what i meant.. just had not had my morning coffee yet XD |
|
|
| Report Abuse |
|
|