UrAn
UrAn

Reputation: 43

Current culture - display euro symbol (€) instead of EUR string

With current culture set to "sk-SK" (Slovakia with currency - euro) I want to show euro symbol (€) instead of "EUR" string when displaying price as currency in Razor with Price.ToString("c").

When I change current culture to, for example German ("de-DE"), the euro symbol (€) is displayed.

I would like to show euro symbol when displaying price with Slovak culture as well (not "EUR" string).

I think this is OS dependent (our OS is Windows Server 2012) but changing default currency suggested by this article: https://www.howtogeek.com/240216/how-to-change-windows-default-currency-from-dollars-to-euros/ (in our case from EUR to €) doesn't change the way currency symbol is displayed. How can I display the currency as € instead of EUR?

Upvotes: 3

Views: 4849

Answers (1)

waka
waka

Reputation: 3417

CultureInfo ci = new CultureInfo("sk-SK");
ci.NumberFormat.CurrencySymbol = "€";
CultureInfo.DefaultThreadCurrentCulture = ci;
double Price = 10.0;
Console.WriteLine(Price.ToString("c"));

This produces the output

10,00 €

Another possibility is to pass the culture info as IFormatProvider in ToString():

Console.WriteLine(Price.ToString("c",ci));

Upvotes: 3

Related Questions