locked
replace all spaces in French numbers RRS feed

  • Question

  • User545494261 posted

    Hi all:

    I have a Number in French a='20 000 000'. I wanto to add 1 to this number and put again it in French:a?'20 000 001'

    I do in Javacript

    a=Intl.NumberFormat('fr-FR').format(parseInt(document.getElementById('"lblndescargas').innerText.replaceAll(' ',''))+1)

    The first time it pass through it it gives 20 000 001. But the second time it gives 21. It seems like the space is not valid as separator.

    Why? How to solve it?

    Thanks in advance.

    Tuesday, March 16, 2021 9:32 AM

Answers

  • User-775646050 posted

    Try using the toLocaleString method. For example:

    function addNumber(x){
     return x.toLocaleString('fr-FR') + 1;
    }
    
    console.log(addNumber('20 000 000'));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2021 9:26 PM