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.
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.
What about:
var value = "8.8 mi";
var number = parseFloat(value); // 8.8
Looks like what you are looking for here.
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)$/;
if it's only mi
at the end then it should work
value= 8.8 mi;
trimValue = value.substr(0,value.length-2);