public class ExperienceTable
{
public static int MaxExperiencePoints;
public static double PercentToNextLevel;
public static void checkLevel(Hero player)
{
if (player.ExperiencePoints >= 0)
{
player.Level = 1;
MaxExperiencePoints = 15;
PercentToNextLevel = player.ExperiencePoints / MaxExperiencePoints;
}
}
Then drawing it to the screen using:
GameRef.SpriteBatch.DrawString(GUIFont, "" + ExperienceTable.PercentToNextLevel, new Vector2((int)player.Camera.Position.X + 1200, (int)player.Camera.Position.Y + 676), Color.White);
How come decimal places don’t show up? Seems like the numbers are being rounded.
By default, the decimal place will not be shown if the double is already a rounded number in the first place. I’m guessing
player.ExperiencePointsis anint. Andintdivided by anotherintwill always result to anint, resulting in a rounded value.Assuming that
player.ExperiencePointsis really anint, and you want to have the fraction when dividing it, you should change the division line to the following:And if you want to have the decimal places displayed eventhough it’s
.00, then change theExperienceTable.PercentToNextLevelto something like the following..ToString("0.00")will convert the double value to a string with 2 decimal places, and will round it to two decimal places if it have to.