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.
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.
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]);