0

I have learned how to make a string variable display in currency format using C2. But how would I be able to display in other currencies such as Euros.

Below is my foundation code to work from

        Console.WriteLine("\nHere is the same value displayed in currency form: " + value.ToString("C2"));
Cœur
  • 37,241
  • 25
  • 195
  • 267
Nathan Cook
  • 31
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [Proper currency format when not displaying the native currency of a culture](http://stackoverflow.com/questions/850673/proper-currency-format-when-not-displaying-the-native-currency-of-a-culture) – Bob Kaufman Mar 10 '16 at 21:49
  • Also `Console.WriteLine(string.Format("{0}Here is the same value displayed in currency form: {1}", Environment.NewLine, value.ToString("C2")));` – Nathan Cooper Mar 10 '16 at 21:52
  • 1
    @BobKaufman - I think these are much closer duplicates since they are .Net specific: [String format currency](http://stackoverflow.com/questions/10416553/string-format-currency) and [Format decimal as currency based on currency code](http://stackoverflow.com/questions/13364984/format-decimal-as-currency-based-on-currency-code). – dbc Mar 11 '16 at 21:40

5 Answers5

4

From the MSDN documentation

// Creates a CultureInfo for English in the U.S.
CultureInfo us = new CultureInfo("en-US");
// Display i formatted as currency for us.
Console.WriteLine(i.ToString("c", us));

So if you want to change it to Euro just change en-US to any country that uses Euro like fr-FR

believe me
  • 910
  • 1
  • 5
  • 24
1

Check this out:

https://msdn.microsoft.com/en-us/library/syy068tk(v=vs.90).aspx

Different Cultures: Allows you to display it in any currency format you want.

Blue Eyed Behemoth
  • 3,692
  • 1
  • 17
  • 27
1

See this msdn article here.

https://msdn.microsoft.com/en-us/goglobal/bb688126.aspx

Essentialy, your machine has a configured Locale which determines how the currency is formatted. If someone in a different country were to run your app, they'd see a different money format (assuming they use different currency).

If your using a webapp, you'll need to get the format of your connected client

bgura
  • 860
  • 15
  • 33
1

You can get Euros for a specific language, by using the C# code you already used and simply adding the language. Microsoft has a useful page on string formatting.

So, to change your code to Euros,it is a simple fix:

Console.WriteLine("\nHere is the same value displayed in currency form: " + value.ToString("C2",fr-FR));
Sierpinski
  • 98
  • 1
  • 8
  • 1
    I'm not sure whether to upvote your answer because it gets the right idea across, or downvote it because you think you're a [C programmer](http://stackoverflow.com/a/11695126/712526). – jpaugh Jan 31 '17 at 16:55
  • 1
    Haha! Wow. Whoops! – Sierpinski Feb 01 '17 at 19:55
-1

Check out this link for currency formatting for certain cultures.

Here's another that has a list for formatting numeric strings.

Hope this helps! :D

Krazy Dev
  • 184
  • 3
  • 16
  • This post contains [no content](https://meta.stackexchange.com/questions/225370/). Please copy in relevant portions from the links you give, in case they bitrot. – jpaugh Jan 31 '17 at 16:50