Separate numbers that have a point in between and save them in variable

0

Look, I have this problem I need to separate this code 5411.21 and save it in different variables, as you can see. in the middle

$(".o tr").each(function () {
    var id = $(this).find("td").eq(0).text();
    var existencia = $(this).find("td").eq(1).text();
    var codigosolo = id.replace("5510.2","5510");
    var tallasolo = id.replace("5510.2","2");
    console.log(codigosolo);
    console.log(tallasolo);
});

is what I try but they are several code so I use each

    
asked by Cesar 16.02.2017 в 22:40
source

2 answers

1

Assuming that "existence" is your code separated by a point, you should use split:

$(".o tr").each(function () {
    var id = $(this).find("td").eq(0).text();
    var existencia = $(this).find("td").eq(1).text();
    var existenciaArray = existencia.split('.');
    var codigosolo = existenciaArray[0];
    var tallasolo = existenciaArray[1];
    console.log(codigosolo);
    console.log(tallasolo);
});
    
answered by 16.02.2017 / 22:45
source
0

you could do a split or use a regular expression in this case for example

new RegExp("(\d{1,})\.(\d{1,})");

this can be useful if you want to separate a more complex string, say a number of type 1,000.00 you could easily separate it with regular expressions.

    
answered by 16.02.2017 в 23:03