From 12105ab85c31a6d02f47bd3a8c6c911e48211542 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 31 Aug 2021 15:08:33 +0900 Subject: [PATCH] Fix rounding error for the first refund option (#2778) (#2810) * Fix rounding error for the first refund option (#2778) * Fix rounding issue --- BTCPayServer/Controllers/InvoiceController.UI.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 796a90d16..5b0e70b26 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -242,10 +242,11 @@ namespace BTCPayServer.Controllers model.RefundStep = RefundSteps.SelectRate; model.Title = "What to refund?"; var paymentMethod = invoice.GetPaymentMethods()[paymentMethodId]; + var cryptoPaid = paymentMethod.Calculate().Paid.ToDecimal(MoneyUnit.BTC); var paidCurrency = - Math.Round(paymentMethod.Calculate().Paid.ToDecimal(MoneyUnit.BTC) * paymentMethod.Rate, + Math.Round(cryptoPaid * paymentMethod.Rate, cdCurrency.Divisibility); - model.CryptoAmountThen = Math.Round(paidCurrency / paymentMethod.Rate, paymentMethodDivisibility); + model.CryptoAmountThen = cryptoPaid.RoundToSignificant(paymentMethodDivisibility); model.RateThenText = _CurrencyNameTable.DisplayFormatCurrency(model.CryptoAmountThen, paymentMethodId.CryptoCode); rules = store.GetStoreBlob().GetRateRules(_NetworkProvider);