Fix rounding error for the first refund option (#2778) (#2810)

* Fix rounding error for the first refund option (#2778)

* Fix rounding issue
This commit is contained in:
Nicolas Dorier 2021-08-31 15:08:33 +09:00 committed by GitHub
parent 723817e3f8
commit 12105ab85c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);