var num = "3.14 is the value of Pi";
alert( parseFloat(num) ); // 3.14
Tip: you can use the isNaN() function to check if a number was successfully extracted.
var num = "The value of Pi is 3.14, approximately"; // would return NaN
num = num.replace( /^\D+/, "" ); // Delete all non-digits from start
alert( parseFloat(num) ); // 3.14!
$num = '3.14 is the value of Pi'; // String starting with a float
echo floatval( $num ); // extracts and prints 3.14