# Solved Calculation giving wrong answer

Discussion in 'Spigot Plugin Development' started by cheesyfreezy, Jun 10, 2016.

1. ### cheesyfreezy

Heey guys,

I am back at it again with a really small problem. I am getting a percentage of a progress from a money balance. So I made a calculation where it should give us the percentage of the money that the player has compared to the money that the player needs to do stuff. But the answer of this calculation is 0.0 for some reason. I checked the calculation in a calculator and the answer was right, but not in the plugin.

Code:

Code (Text):
DecimalFormat format = new DecimalFormat("#.0");
double calculation = 100 / getConfig().getInt("prison-ranks." + rank) * moneyConfig.getInt(players.getUniqueId().toString());
String percentage = format.format(calculation).replace(",", ".");

2. ### MiniDigger Supporter

thats a typical beginner mistake your are making there. your are deviating an int by and int multiplied by an int.
int*int=int. int/int = int. so everything after the comma gets dropped. what you want to do is dividing a double by an int. double/int = double.
all what you have to do is to add a '.' after the 100 to make it a double literal.

• Informative x 1
3. ### Foulwerp

Just use
Code (Text):
getConfig().getDouble("");
So you are only working with doubles.

The person before me was informative as well, when working with different number types your going to run into this problem. So make sure your not casting your number to a different type when working with multiple types.

4. ### cheesyfreezy

Thank you guys! Little mistakes can happen!