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.

NoviceToDotNet
  • 10,387
  • 36
  • 112
  • 166

4 Answers4

5

What about:

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

Looks like what you are looking for here.

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
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)$/;
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
2

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

value= 8.8 mi;
trimValue = value.substr(0,value.length-2);
ashishmaurya
  • 1,196
  • 10
  • 18
1
value = value.substr(0, value.length - 2);
Ryan
  • 1,356
  • 2
  • 10
  • 18