Round down balance when converting to double (#2135)

This commit is contained in:
Max Lee 2018-08-21 23:45:58 +01:00 committed by Ali 'SupaHam' M
parent 3b1eb683e1
commit f569b89d8f

View File

@ -78,7 +78,14 @@ public class Economy {
*/
@Deprecated
public static double getMoney(String name) throws UserDoesNotExistException {
return getMoneyExact(name).doubleValue();
BigDecimal exactAmount = getMoneyExact(name);
double amount = exactAmount.doubleValue();
if (new BigDecimal(amount).compareTo(exactAmount) > 0) {
// closest double is bigger than the exact amount
// -> get the previous double value to not return more money than the user has
amount = Math.nextAfter(amount, Double.NEGATIVE_INFINITY);
}
return amount;
}
public static BigDecimal getMoneyExact(String name) throws UserDoesNotExistException {