I am still learning the basics with C# and i am completely baffled by this issue. I am making a program in C# using Windows Forms to convert USD to EURO and vice versa. I am rounding both outputs to the 2nd decimal using the Math.Round method. The issue i am having is when i convert the output to a string using the ".ToString()" method using the "\u20AC" function, it only displays the EURO symbol and not the amount. But when i take out the "\u20AC" function, it displays the amount and not the EURO symbol. Now the really interesting part is, when i use the exact same line of code when i convert EURO to USD, the output comes out perfectly fine with the dollar sign and the amount. Am i doing something wrong here? Here is my Code:
private void btnEXC1_Click(object sender, EventArgs e)
{
double USD = Convert.ToDouble(tbUSD.Text);
double EURO;
EURO = USD * 1.18113;
lblUSDTOEURO.Text = Math.Round(EURO,2).ToString("\u20AC");
}
private void btnEXC2_Click(object sender, EventArgs e)
{
double EURO = Convert.ToDouble(tbEURO.Text);
double USD;
USD = EURO * 0.846648;
lblEUROTOUSD.Text = Math.Round(USD, 2).ToString("c");
}
Use this format string for euros: "\u20AC0.00"
.
In this mask the 0.00
part represents the display format for a number.
In your mask there is no display format for a number, therefore it displays as the only char.
The "c"
format string is a predefined format that is intended for currency values: MSDN.