Developer forum

Forum » Ecommerce - Standard features » CurrencyService.FormatCurrency reversing symbol placement

CurrencyService.FormatCurrency reversing symbol placement

Mikkel Belchuke
Mikkel Belchuke
Reply

Hi. 

If we use Dynamicweb.Ecommerce.International.CurrencyService.FormatCurrency(currency, value, true), the currency symbol switch from: "n$" to "$n".

Before using FormatCurrency = 1.000 kr.

After using FormatCurrency = kr. 1.000

This is happening if we use Regional info (see attachment). 

If we set this to "none" it will format as expected. 

MicrosoftTeams-image.png

Replies

 
Nicolai Pedersen
Reply

CurrencyService.FormatCurrency is the fallback to the 'old' version of currency formatting.

Use CurrencyService.Format and it will follow the rest of the rules in currency roundings.

 
Mikkel Belchuke
Mikkel Belchuke
Reply

Hi Nicolai.

The use of CurrencyService.Format does not seem to make a difference. Is it not possible to use Regional Info when using this service? 

 
Nicolai Pedersen
Reply

No - it will use the region set on the currency. The entire point...

But why would you call that method if you need to do something else? 

Here is the code - make it your own:

if (!string.IsNullOrEmpty(currency?.CultureInfo) && currency.CultureInfo.Contains("-"))
            {
                var formatInfo = NumberFormatCache.GetCache(currency.Code);
                if (currency.Rounding is object && !string.IsNullOrEmpty(currency.Rounding.Id))
                {
                    value = Round(currency, value);
                }

                if (showSymbol)
                {
                    if (currency.UseCurrencyCodeForFormat)
                    {
                        return value.ToString("C", formatInfo).Replace(formatInfo.CurrencySymbol, currency.Code);
                    }
                    else
                    {
                        return value.ToString("C", formatInfo);
                    }
                }
                else
                {
                    return value.ToString("N", formatInfo);
                }
            }

 

You must be logged in to post in the forum