3

i have a following value i want to trim "mi" and other white values from the below figure.

value= 8.8 mi

the value may change every time but will come with mi.

2

4 Answers 4

5

What about:

var value = "8.8 mi";
var number = parseFloat(value); // 8.8

Looks like what you are looking for here.

Sign up to request clarification or add additional context in comments.

Comments

3

Use regex to remove the text from the end of the string:

var expr = / mi$/;
var value2 = value.replace(expr, "");

And like h2ooooooo commented, you can use a group to match on:

var expr = / (hr|mi|sec)$/;

2 Comments

And for "other white values": / (mi|foo|bar)$/.
@h2ooooooo: Thanks. Put your remarks in the answer.
2

if it's only mi at the end then it should work

value= 8.8 mi;
trimValue = value.substr(0,value.length-2);

Comments

1
value = value.substr(0, value.length - 2);

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.