From 8a89be16365197784a797ff9fb41500aeec3f1d0 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 2 Nov 2023 11:10:39 -0400 Subject: [PATCH] fix too much precision calculating security deposit --- core/src/main/java/haveno/core/trade/HavenoUtils.java | 3 ++- core/src/main/java/haveno/core/util/coin/CoinUtil.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/HavenoUtils.java b/core/src/main/java/haveno/core/trade/HavenoUtils.java index 11796b92fb..681046aaee 100644 --- a/core/src/main/java/haveno/core/trade/HavenoUtils.java +++ b/core/src/main/java/haveno/core/trade/HavenoUtils.java @@ -38,6 +38,7 @@ import haveno.core.util.ParsingUtils; import haveno.network.p2p.NodeAddress; import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; import java.net.URI; import java.security.PrivateKey; import java.text.DecimalFormat; @@ -122,7 +123,7 @@ public class HavenoUtils { } public static BigInteger xmrToAtomicUnits(double xmr) { - return BigDecimal.valueOf(xmr).multiply(new BigDecimal(XMR_AU_MULTIPLIER)).setScale(8).toBigInteger(); + return BigDecimal.valueOf(xmr).setScale(8, RoundingMode.DOWN).multiply(new BigDecimal(XMR_AU_MULTIPLIER)).toBigInteger(); } public static long xmrToCentineros(double xmr) { diff --git a/core/src/main/java/haveno/core/util/coin/CoinUtil.java b/core/src/main/java/haveno/core/util/coin/CoinUtil.java index 7e5a2a87e9..ff068f0663 100644 --- a/core/src/main/java/haveno/core/util/coin/CoinUtil.java +++ b/core/src/main/java/haveno/core/util/coin/CoinUtil.java @@ -29,6 +29,7 @@ import org.bitcoinj.core.Coin; import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; import java.text.DecimalFormat; import static com.google.common.base.Preconditions.checkArgument; @@ -76,7 +77,7 @@ public class CoinUtil { */ public static BigInteger getPercentOfAmount(double percent, BigInteger amount) { if (amount == null) amount = BigInteger.valueOf(0); - return BigDecimal.valueOf(percent).multiply(new BigDecimal(amount)).toBigInteger(); + return BigDecimal.valueOf(percent).multiply(new BigDecimal(amount)).setScale(8, RoundingMode.DOWN).toBigInteger(); } public static BigInteger getRoundedAmount(BigInteger amount, Price price, long maxTradeLimit, String currencyCode, String paymentMethodId) {