Converter into euro c#

22,092

Solution 1

You need to specify the Culture, to a String.Format

Something like

//use any european culture
var cultureInfo = CultureInfo.GetCultureInfo("fr-FR"); 
Console.WriteLine(String.Format(cultureInfo, "{0:C} Euro", result));

An alternative

Console.WriteLine(string.Format("€{0:N2} Euro", result));

Format to 2 decimal places (prefixed by €)

Solution 2

From: MSDN:

"C" or "c" : Currency Result: A currency value. Supported by: All numeric types. Precision specifier: Number of decimal digits. Default precision specifier: Defined by NumberFormatInfo.CurrencyDecimalDigits.

More information: The Currency ("C") Format Specifier.

123.456 ("C", en-US) -> $123.46  
123.456 ("C", fr-FR) -> 123,46 €  
123.456 ("C", ja-JP) -> ¥123  
-123.456 ("C3", en-US) -> ($123.456)  
-123.456 ("C3", fr-FR) -> -123,456 €  
-123.456 ("C3", ja-JP) -> -¥123.456  
Share:
22,092

Related videos on Youtube

Nelly
Author by

Nelly

Updated on October 29, 2020

Comments

  • Nelly
    Nelly over 3 years

    I have to convert from Lei into euro by using string formatting for currency. My method is:

    public static void ConvertFromRonEur()
        {
            //string amount = string.Format("{0:C}");
            double result;
            Console.WriteLine("Lei: ");
            double quantity;
            double euro = 0.22D;
            quantity = double.Parse(Console.ReadLine());
            result = quantity * euro;
            Console.WriteLine(("{0:C} Euro"), result);
        }
    

    When I run the result is:

      Lei:
      10
      $2,20 Euro
    

    How can I have only the 2,20 Euro result, but to use the string formatting currency? Thank you.