-
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.
-
Use [code] tags to post code.
"in advance", not "in advanced".
Use Math.ceil to round a float to the next integer.
-
could you give me an example?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|