I might have been staring at my screen too much because of programming, but I really don't understand what is happening here.
I'm trying to make a game and calculate the percentage progress it takes to level up. Here are my methods:
public static int currentLevelInt(Integer XP){
return (int)(1 + sqrt(1+8*XP/50))/2;
}
public static double currentLevelDouble(Integer XP){
return (1 + sqrt(1+8*XP/50))/2;
}
public static int getPercentage(Integer XP){
double currentLevel = currentLevelDouble(XP);
int nextLevel = currentLevelInt(XP)+1;
return (int)(100-((nextLevel-currentLevel)*100));
}
Let's say I have 54 XP. Then these are the expected values:
currentLevelInt(54) = 2
currentLevelDouble(54) = 2.05241747
(int)(100-(((currentLevelInt(54)+1)-currentLevelDouble(54))*100)) = 5%
//+1 because I need the next Level
But these are the values I get returned:
currentLevelInt(54) = 2
currentLevelDouble(54) = 2.0
(int)(100-(((currentLevelInt(54)+1)-currentLevelDouble(54))*100)) = 0%
//+1 because I need the next Level
I don't understand what is going on? I'm passing the double as double, why would it be rounded off to 2.0?