I have multiple strings that looks like these: 550 e, 1,550 e, 1.550,00 e I need to convert it to numbers so I can compare its values.
I removed currency part (e) w/ split()
and then join()
but how to get numbers from that?
I have multiple strings that looks like these: 550 e, 1,550 e, 1.550,00 e I need to convert it to numbers so I can compare its values.
I removed currency part (e) w/ split()
and then join()
but how to get numbers from that?
Try using something like :
var integer = parseInt(yourString, 10);
for decimal numbers :
var decimal= parseFloat(yourString);
use Regular Expression
to capture digits followed by optional decimal.
var regex = /\d+.?\d+/g;
const arrofStrings = ["550 e", "1,550 e", "1.550,00 e"];
const numbers = arrofStrings.map((str) => {
str = str.replace(',', '');
return Number(str.match(regex));
});
console.log(numbers);