1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Round and convert float to integer?

Discussion in 'Civ5 - SDK / LUA' started by skweetis, Nov 30, 2010.

  1. skweetis

    skweetis Chieftain

    Joined:
    Mar 14, 2008
    Messages:
    58
    Location:
    Canada
    Hey all,

    Im looking for an easy way to round a decimal number to a whole number in lua , any hints?

    Cheers!
     
  2. MouseyPounds

    MouseyPounds Prince

    Joined:
    Nov 8, 2010
    Messages:
    417
    Location:
    Maryland, USA
    To simply round a number you can use math.floor(x + .5). No actual "conversion" is necessary though since lua does not differentiate between integers and floats (all numbers are represented internally as doubles.)
     
  3. skweetis

    skweetis Chieftain

    Joined:
    Mar 14, 2008
    Messages:
    58
    Location:
    Canada
    awesome, thank you!

    gotcha, searched through the document again and found the index with all the math and other functions listed.... can't believe I missed it...
     
  4. Gangor

    Gangor King

    Joined:
    Jan 21, 2002
    Messages:
    825
    Location:
    Berks, UK
    it's also possible to round up, or to the closest whole number, iirc. Take a look in Lua's math standard library
     

Share This Page