0

I have a string that is a numbrer str='20.000.000' I want another string that adds 1 to that number str='20.000.001' i do

document.getElementById('lblndescargas').innerHTML=Intl.NumberFormat('de-DE').format(parseInt(document.getElementById('lblndescargas').innerHTML.replace('.',''))+1)

But it replace only the first '.'.

How to resolve it?

Thanks a lot!

volar.2016
  • 13
  • 3
  • I would suggest you to reduce it to the minimal problem. For that I'd suggest you to split it up into multiple steps (and multiple lines). Then you would see more clear what fails and would only need to ask about that (or search about it on Google/Stackoverflow, it should be rather easy to find. And it's good practice for an essential programming skill) – A_A Mar 14 '21 at 08:19
  • Does this answer your question? [How to replace all occurrences of a string in Javascript?](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript) – A_A Mar 14 '21 at 08:21

2 Answers2

0

use the global flag

const input = "20.000.000";
const output = Number(input.replace(/\./g, "")) + 1;

console.log(output); // 20000001

or in the given example:

parseInt(document.getElementById('lblndescargas').innerHTML.replace(/\./g,''))+1
eamanola
  • 364
  • 1
  • 10
0

use

innerHTML.replaceAll('.','')

Mahamudul Hasan
  • 2,745
  • 2
  • 17
  • 26