I need to display current exchange rates on my application.
Is it possible to retrieve the exchange rate from http://www.xe.com (XE Converter)
Here what I tried:
public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency)
{
string Output = "";
string fromCurrency1 = comboBox1.Text;
string toCurrency1 = comboBox2.Text;
decimal amount1 = Convert.ToDecimal(textBox1.Text);
// For other currency symbols see http://finance.yahoo.com/currency-converter/
// Construct URL to query the Yahoo! Finance API
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = string.Format(urlPattern, fromCurrency1, toCurrency1);
// Get response as string
string response = new WebClient().DownloadString(url);
// Convert string to number
decimal exchangeRate =
decimal.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
// Output the result
Output = (amount1 * exchangeRate).ToString();
textBox2.Text = Output;
return Output;
}
With this code I am not having the full output... the decimal part is not
showing...