Extract decimal from a string

-2

I have a very specific question for JavaScript:

I have the following string:

var prueba ="Hola mundo 5.26"

I need to extract the decimal number from that string. How can this be done?

Thank you very much

    
asked by Jorge Leonardo Cardenas Monten 28.10.2018 в 22:43
source

2 answers

0

Try this regular expression

var resultado = prueba.match(/[0-9]*\.[0-9]*/g)
    
answered by 28.10.2018 / 22:52
source
0

You can get the number within a string like this:

var prueba = "Hola mundo 5.26";
var numero = parseFloat(prueba.match(/\d+(\.\d+)?/g));

Good luck!

    
answered by 28.10.2018 в 22:59