Google Exchange Rate API

If you type “1 USD to CAD” into Google it will return the exchange rate for USD/CAD. This is a very cool feature, and like many of Googles features it’s available as an API for you to use.

The API is rest based and it returns a JSON object with the details.

To use the API you just need to do this:


The number 1 before USD is the amount of dollars or quantity.

When you do this you get back the following JSON object:

{lhs: “2 U.S. dollars”,rhs: “1.89159282 Canadian dollars”,error: “”,icc: true}

As you can see the result is called rhs, but it combines the resulting value with the text “Canadian Dollars”. Not sure why Google would merge a decimal and string like that instead of making them discrete fields, but in our implementation we will remove the string and store the result as a decimal.


This class has just one method: Convert. It takes the amount of dollars to convert (could be fractional such as 1.25 etc..) and the from currency (USD) and the to currency (CAD).

using System.Net;
using System.Text.RegularExpressions;

namespace CurrencyConverter
    public static class ExchangeRateCalculator
        public static decimal Convert(decimal amount, string fromCurrency, string toCurrency)
            WebClient web = new WebClient();

            string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);

            string response = web.DownloadString(url);

            Regex regex = new Regex("rhs: "(d*.d*)");
            Match match = regex.Match(response);

            decimal rate = System.Convert.ToDecimal(match.Groups[1].Value);

            return rate;

Categories:   Finance


  • Posted: May 2, 2011 15:42


    Exactly what I needed and it's even with the language I'm using! Thx!
  • Posted: May 14, 2011 18:33

    Deepesh Kapadia

    Hi, Thanks for this. This is a really nice snippet. However there seems to be a problem as when I enter amounts in thousand and the result is in thousands it throws an exception as follows: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) Any workaround for the above error?
  • Posted: May 27, 2012 15:37


    Would you possibly offer me the full currency rate code in "Newbie HTML" (NOT php) so that I could add it to my site as "John Doe HTML? I would like simply to input 'Amount' 'then choose drop-down 'From currency' to 'To currency' then see the results on that page, hopefully in Ajax, so as to have an undisturbed layout using a single- page "Get the rate" operation. I appreciate your genius, but this scripting is way over my head... Hoping and thanking in advance, Hendrik
  • Posted: October 4, 2012 22:13


    If anyone is looking for a php solution, here it is: You can send a curl request to the google api and get the result. Here is an example: function currency($from_Currency,$to_Currency,$amount) { $amount = urlencode($amount); $from_Currency = urlencode($from_Currency); $to_Currency = urlencode($to_Currency); $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency"; $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); $data = explode('"', $rawdata); $data = explode(' ', $data['3']); $var = $data['0']; return round($var,2); } echo currency("USD","PHP",1.00);
  • Posted: October 26, 2012 08:05


    Strange, if I use AWG currency (Aruba florin) it gives an error, but AWG is a correct currency code!
  • Posted: March 2, 2013 03:41


    is it permanent API ? is it suitable for commercial use and free ?
    • Posted: March 2, 2013 13:27

      Kelly Elias

      No. It's unofficial so could stop whenever, and it's definitely not good for commercial purposes.
      • Posted: August 19, 2016 01:06


        It seem to have been removed, if I put the URL http://www.google.com/ig/calculator?hl=en&q=1USD%3D%3FCAD into my browser, it just goes to the Google home page :-(
  • Posted: March 3, 2013 21:53


    I have another one of yahoo. http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={0}{1}=X where {0}=currency from(e.g. USD) and {1}=currency to(e.g. EUR) is it suitable for commercial use ? b'coz i didn't find any documentation about it. please help as soon as possible. and if u have one for commercial use please suggest one.
  • Posted: August 7, 2013 08:26


    Your code dosen't work on my pc. So I changed this line to get work with .net 4 Regex regex = new Regex("rhs: \"" + @"(\d*\.\d)");
  • Posted: November 1, 2013 18:07


    Thank you! This is a big time-saver for me. The response format must have changed because the regular expression doesn't seem to work. I tried KOCHOL's solution but I only got the value to one decimal place. I cant use advanced regular expressions so this was my noob solution: string response = web.DownloadString(url); string[] processingArray = Regex.Split(response, @"rhs: \"""); string processingString = processingArray[1]; processingArray = Regex.Split(processingString, @" "); decimal rate = Convert.ToDecimal(processingArray[0]); return rate;