From db1cf5c2ce2a8c88e3fa1d8b16f8d173794f7792 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 19 Oct 2017 16:01:45 +0900 Subject: [PATCH] format currency correctly --- .../Controllers/InvoiceController.UI.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 832b09ac5..8d6ab411b 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -92,6 +92,27 @@ namespace BTCPayServer.Controllers return View(model); } + + static Dictionary _CurrencyProviders = new Dictionary(); + private IFormatProvider GetCurrencyProvider(string currency) + { + lock(_CurrencyProviders) + { + if(_CurrencyProviders.Count == 0) + { + foreach(var culture in CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => !c.IsNeutralCulture)) + { + try + { + _CurrencyProviders.TryAdd(new RegionInfo(culture.LCID).ISOCurrencySymbol, culture); + } + catch { } + } + } + return _CurrencyProviders.TryGet(currency); + } + } + [HttpGet] [Route("i/{invoiceId}")] [Route("invoice")] @@ -123,7 +144,7 @@ namespace BTCPayServer.Controllers ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds), MaxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds, ItemDesc = invoice.ProductInformation.ItemDesc, - Rate = invoice.Rate.ToString(), + Rate = invoice.Rate.ToString("C", GetCurrencyProvider(invoice.ProductInformation.Currency)), RedirectUrl = invoice.RedirectURL, StoreName = store.StoreName, TxFees = invoice.TxFee.ToString(),