Summary

Uses the Yahoo! Finance API to convert a value from one currency to another based on the current exchange rate.

Code (C#)

// For other currency symbols see http://finance.yahoo.com/currency-converter/
const string fromCurrency = "USD";
const string toCurrency = "EUR";
const double amount = 49.95;

// Clear the output editor
Output.Clear();

// 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, fromCurrency, toCurrency);

// Get response as string
string response = new WebClient().DownloadString(url);

// Convert string to number
double exchangeRate = double.Parse(response, System.Globalization.CultureInfo.InvariantCulture);

// Output the result
Output.Text = String.Format("{0} {1} = {2} {3}", amount, fromCurrency, amount * exchangeRate, toCurrency); 
Input Type: Nothing, Output Type: Plain Text

Download Project File

File: Currency_converter.dvp (2.04 KB)

To open this file, DataVoila must be installed on your computer. If this is not yet the case, please click here to download the free demo version.