Sagar
Sagar

Reputation: 69

How to extract float value from a string in Jquery

My string contain following value in it.

var Test = "3700 NO LAND VALUE (Lease Property) (0.10)"

Now how can i retrieve only 0.10 from above string. output must be 0.10 not 3700

Upvotes: 2

Views: 924

Answers (3)

Dexter Bengil
Dexter Bengil

Reputation: 6615

You can use this regex

var Test = "3700 NO LAND VALUE (Lease Property) (0.10)"
var regExp = /\(([0-9|.]+)\)/;  
var matches = regExp.exec(Test);
var result = matches[1];
console.log(result);

Upvotes: 0

Carle B. Navy
Carle B. Navy

Reputation: 1156

You can use regular expressions like this:

var Test = "3700 NO LAND VALUE (Lease Property) (0.10)";
var Regex = /([\d]+[.][\d]+)/g;

var output = Regex.exec(Test);

alert(output[1]);

Upvotes: 0

Razzildinho
Razzildinho

Reputation: 2584

You can use a regular expression to extract a float.

var re = /\d+\.\d+/g;
var test = "3700 NO LAND VALUE (Lease Property) (0.10)";
var floats = test.match(re);

Upvotes: 1

Related Questions