A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: rounding up?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17

    rounding up?

    This is the equation I have, and I'm trying to figure out how to always force it to round up..

    if(combobox.selectedItem.label == "Chicken"){finalResults.text=(desLvl-parseFloat(CurrExp.text))/monsterExp+" Chickens left to kill"};

    Thanks in advanced.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Use [code] tags to post code.

    "in advance", not "in advanced".

    Use Math.ceil to round a float to the next integer.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    could you give me an example?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Code:
    if (combobox.selectedItem.label == "Chicken"){
      var chickensLeft:int = Math.ceil((desLvl - parseFloat(CurrExp.text))/monsterExp);
      finalResults.text = chickensLeft + " Chickens left to kill";
    }
    You should also have a currExp (or some other name) numerical variable around somewhere which you should use to set the CurrExp textfield. You should not use the textfield value as your data storage. You can avoid parsing the number all the time for one thing. But mostly, it's just cleaner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center