Convert millions of STRING to INT - Javascript

Asked

Viewed 72 times

-1

I have a string 123.456.789 and when using parseint is returning 123456, how to do to return 123456789 ?

  • 1

    Remove the points with replace.

  • Probably it is considering the last point as decimal point and then when you convert to integer it despises the decimal part getting only the whole part.

1 answer

3

In this example, I first did the formatting by removing the stitches, then did the conversion.

var numeroFormatado = `123.456.789`.replace(/\./g, ``)

numero = parseInt(numeroFormatado)

console.log(numero)

  • Exactly, the last point is seen as decimal place in the English language

Browser other questions tagged

You are not signed in. Login or sign up in order to post.