From f569b89d8f4eef495cfff2ee201d5338014280cc Mon Sep 17 00:00:00 2001 From: Max Lee Date: Tue, 21 Aug 2018 23:45:58 +0100 Subject: [PATCH] Round down balance when converting to double (#2135) --- Essentials/src/com/earth2me/essentials/api/Economy.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index cbd6215b2..e55aad559 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -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 {