1

I am writing a math paper where i would like to display my calculations (formulas) separately from the solution.

I am currently working in Google Sheets.

The end goal would be to have one column with formulas and one column with answers.

I tried to work with GS to write a function that would take the string value from A1 and evaluate it in the B1 column.

I used this simple script that i found on: https://support.google.com/docs/thread/13826624/evaluate-string-as-formula?hl=en

function run(input){
  return eval(input);
}

It works with simple calculations like division, multiplication, addition and subtraction.

But the script doesn't solve basic exponents like 1 * 10^3 (it gives me 9). And square roots like sqrt(9) (gives me an #error)

I'm not sure which way to go from here.

andrewJames
  • 19,570
  • 8
  • 19
  • 51
RustyJames
  • 123
  • 7
  • You can use the approach shown here: [How to use a formula written as a string in another cell](https://stackoverflow.com/questions/36012775/how-to-use-a-formula-written-as-a-string-in-another-cell-evaluate-for-google-sp). One of the answers shows a small script which you can adapt to your needs. It works for the examples you show in your question (I tested my version of it). – andrewJames Jun 12 '21 at 17:46

1 Answers1

4

The easiest solution would probably be to work the other way around: write your formulas normally, and use the formulatext() spreadsheet function to display the formula in an adjacent cell.

doubleunary
  • 13,842
  • 3
  • 18
  • 51