0

I have a variable with this string:

Total price: 65.09 GBP

How do I extract the number 65.09 from this string and store in another variable? P.s: just the number with 2 decimals, don't need the currency after it, also, the value can be anything from 0 to 1 billion, so it could have commas also to separate the numbers.

I saw some other posts regarding this same issue using split with delimiters or substr(), but I could not adapt it to my scenario, thanks!

1 Answer 1

1

I would use a regular expression to extract the number:

<tr>
  <td>store</td>
  <td>Total price: 65.09 GBP</td>
  <td>v1</td>
</tr>
<tr>
  <td>storeEval</td>
  <td>storedVars['v1'].match(/[\d.,]+/)</td>
  <td>v2</td>
</tr>
<tr>
  <td>echo</td>
  <td>${v2}</td>
  <td></td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.