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.
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 €)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With