How to round in Lua?

  • Videogamer555
    2nd Jan 2012 Member 0 Permalink
    I can use math.floor(ipart.fpart) and it will take the number and force it down to ipart. If I use math.ceil(ipart.fpart) it will force it up to ipart+1 unless fpart=0.


    But what I want is to have it properly round to the nearest integer so that if fpart is <0.5 it will round down to ipart, while if fpart>=0.5 it will round up to ipart+1. How do I do this in Lua? Is there a math function for this?
  • jacksonmj
    2nd Jan 2012 Developer 0 Permalink
    There isn't a function for it, use math.floor(x+0.5)
  • Videogamer555
    2nd Jan 2012 Member 0 Permalink
    Thanks, I eventually figured that out.
  • MasterMind555
    2nd Jan 2012 Member 0 Permalink

    Videogamer555:

    Thanks, I eventually figured that out.
    Can you please search before posting one thread for every question you have? It's annoying me that you make 10 threads per day on lua scripts... At least please put all your questions in the same thread