Kevin Bradshaw
Kevin Bradshaw

Reputation: 6427

.net display localised currency format without currency symbol

I have a localised site that needs to display a currency field.

The currency will remain the same and does not change per culture

I have tried to format the currency like this:

@String.Format(CultureInfo.CurrentCulture, "{0:C}", item.GrossPayment)

but this does not work, because it displays the currency symbol native to that culture.

I want to display €12 but the above displays ¥12

So, the format is what I want, but without the currency symbol which I can just hardcode

so next I tried this:

€@String.Format(CultureInfo.CurrentCulture, "{0:N}", item.GrossPayment)

In ja-JP

€12.00

gets displayed so this gets over my currency symbol problem, but now the format is wrong as in the ja-JP culture there should be no decimal point or trailing zeroes it should display as

€12

Any ideas how I can preserve the format while specifying my own currency symbol in a view?

Upvotes: 1

Views: 294

Answers (1)

Dávid Molnár
Dávid Molnár

Reputation: 11573

You can change the currency symbol in the culture. Create a copy of the culture and then change whatever you want:

var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.NumberFormat.CurrencySymbol = "€";
@String.Format(culture, "{0:C}", 12);

Maybe you could preserve the copy of the culture in some static variable, so won't have to clone on every request...

Upvotes: 1

Related Questions