0

I have a cell in google sheets that says recipe items like "24 oz". Is there a way to parse out the 24 to a variable in my script?

I am trying to use this variable in a simple math formula. It is dynamic, that is why I need to write code for it.

EylM
  • 5,967
  • 2
  • 16
  • 28

1 Answers1

0
var your_input = "24 oz"; 
//find spaces and convert the input into an array
// each time split(" ") find a space , it add an element to the array
var array = your_input.split(" ");
// now array contain two elements
// array[0]="24" and array[1]="oz"
//now we parse "24" into a Long so we can use it in math operations
var result = parseInt(array[0]);
phoenixstudio
  • 1,776
  • 1
  • 14
  • 19