【发布时间】:2017-04-23 16:02:29
【问题描述】:
我需要在我的应用程序上显示当前汇率。
是否可以从http://www.xe.com 检索汇率(XE 转换器)
这是我尝试过的:
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;
}
使用此代码,我没有完整的输出...小数部分没有
显示...
【问题讨论】: