Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Find another Google search query that will return the results (I'm not afraid of doing some html scraping.)
  • Find another api provided by someone else (something like YQL - I am already using them for currency conversion
  • Use a pure javascript calculator - Is there a good javascript library or script you can recommend? (Most scripts I've seen are just doing eval(), which I can't use, and most seem to be tutorials to introduce javascript.)

Any suggestions?

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

  • 10+10
  • 5*9+(sqrt 10)^3
  • 100 lbs in kg
  • http://www.googleguide.com/help/calculator.html



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"
like image 676
Redzarf Avatar asked Nov 02 '22 11:11

Redzarf


1 Answers

You can use the math.js library:

http://mathjs.org/

It supports units and has a powerful expression parser.

like image 134
Jos de Jong Avatar answered Nov 08 '22 07:11

Jos de Jong