【发布时间】:2026-02-23 02:35:01
【问题描述】:
public PriceTable ConvertToUSDollar(decimal Amount,string Currency)
{
try
{
var toCurrency = "USD";
var fromCurrency = "AUD";
string url = string.Format("http://www.google.com/ig/calculator?hl=en&q= {2}{0}%3D%3F{1}", fromCurrency .ToUpper(), toCurrency.ToUpper(), 1000);
WebClient web = new WebClient();
string response = web.DownloadString(url);
Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
Match match = regex.Match(response);
string rate = (match.Groups[1].Value.Trim());
rate = Regex.Replace(rate, @"\s", "");
decimal Value = Convert.ToDecimal(rate);
var pricetable = new PriceTable()
{
Price = Value
};
return pricetable;
}
catch(Exception e) {
throw new Exception("Error Occoured While Converting");
}
}
在这种情况下,生成的货币不包含十进制值。如何获得包含小数部分的确切货币?
【问题讨论】: