4

Google Calculator formats math expressions this way:

2+2/2 ---> 2 + (2 / 2)
2+2/2*PI ---> 2 + ((2 / 2) * PI)

In others words - it adds brackets. Are there any similar PHP or JavaScript solutions to do the same thing?

3
  • please give your question a context e.g. i want strings formatted and displayed back to the user in the browser. is this what you're trying to achieve? Dec 1, 2010 at 10:09
  • should you try an javascript event function (onkeypress, onchange)? and define the rules -- while plus signal before some number keep adding -- if division signal is found then put the brackets... but of course in somewhere someone has done the done.. Dec 3, 2010 at 16:26
  • @murraybiscuit: Yes, I want a javascript/PHP function that returns formatted math expression as string.
    – Ken
    Dec 4, 2010 at 15:53

2 Answers 2

1

Yes; quickest and easiest way to not code it yourself (like how Google did) is to use MathML.

Hope this helps!

1

surely you could just query the calendar via curl + ajax / postback? the result is a json array with left, right, error etc.

query example: http://www.google.com/ig/calculator?q=5*9%2B%28sqrt+10%29^3%3D

php / curl sample: http://www.dynamicguru.com/php/currency-conversion-using-php-and-google-calculator-api/#more-285

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.