Post your current code.
|
Is there any way to convert a double to an int?
I made a code that should calculate the hits of a player, and then return them as ints having no decimals, because the hits are not having decimals.
Is there a way to do this?
This is my current code:
Code:public int effectiveStrength() { /** * Calculating the first step in the runescape max hit formula. * Prayer, Potions and "otherBonus" will be added later. */ int potionBonus = 0; int prayerBonus = 0; int otherBonus = 0; double effectiveStrength2 = (((getLevelForXP(playerXP[2])+potionBonus)*prayerBonus*otherBonus)+playerBonus[getBonusFromFightType]); int result = Math.floor((int)effectiveStrength2); return result; }
Post your current code.
You already cast a double to an int in your code...
Mads, what's the error?
Math.floor(...) is a double. You've got to cast that to an integer, not 'effectiveStrength2'.
Code:public int effectiveStrength() { /** * Calculating the first step in the runescape max hit formula. * Prayer, Potions and "otherBonus" will be added later. */ int potionBonus = 0; int prayerBonus = 0; int otherBonus = 0; double effectiveStrength2 = (((getLevelForXP(playerXP[2])+potionBonus)*prayerBonus*otherBonus)+playerBonus[getBonusFromFightType]); int result = (int)Math.floor(effectiveStrength2); return result; }
heres an example how to do it:
Code:int number1; double number2 = 1.54; number1 = (int)number2;
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |