javascriptweb-applicationscalculatorigoogle

Alternative to Google calculator API


I'm working on a webapp that for the last 2 years has used the unofficial API for Google Calculator like: http://www.google.com/ig/calculator?hl=en&q=

Now that iGoogle has been closed last week (https://support.google.com/websearch/answer/2664197) the google calculator api doesn't work either.

What's the best alternative for doing a javascript calculator? (Where I give it a string and it evaluates the answer.)

Some ideas I've had:

Any suggestions?

Here are some sample queries that the Google Calculator handles. The more I can do, the better:



YQL currency conversion info for anyone that comes looking for it later: https://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20Rate%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22nzDgbp%22%29

"https://query.yahooapis.com/v1/public/yql?q=select%20Rate%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22" + from + to + "%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=callBackFunctionName"

Solution

  • You can use the math.js library:

    http://mathjs.org/

    It supports units and has a powerful expression parser.