0

I have 84000000 and I want to display 84 000 000 in DOM.

var num = 84000000;
$('body').text(num.toLocaleString('fr-FR')); //gives 84000000 but
console.log(num.toLocaleString('fr-FR'));  //gives 84 000 000
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

I get this: enter image description here Same thing in all browsers I have.

What is wrong? How to show 84 000 000 in DOM using.toLocaleString ?

Cutis
  • 949
  • 1
  • 13
  • 32
  • I see correctly in both – Brank Victoria May 07 '19 at 08:53
  • I changed the text of the tags on this page, in the console, and get the desired output – Matt Ellen May 07 '19 at 08:53
  • Executing the code spinet shows the correct output!!! – Mamun May 07 '19 at 08:55
  • I am confused. Maybe can this be because i use nodejs? I try 'new Intl.NumberFormat('fr-FR').format(num);' but I have the same issue. What could be the reason of that please? – Cutis May 07 '19 at 08:56
  • @Cutis You could try using `.html(num.toLocaleString('fr-FR').replace(/\s/g, ' '));` – nick zoum May 07 '19 at 09:01
  • This is my first post about the issues I have https://stackoverflow.com/questions/55948982/tolocalestringfr-fr-not-showing-spaces-in-amount-but-working-in-console/56018982#56018982, could you help to find what is wrong? thanks – Cutis May 07 '19 at 09:01
  • @Cutis I see you are using `replace(/\s/g, '')` which will fully remove all the spaces. Use `.replace(/\s/g, ' ')` instead. – nick zoum May 07 '19 at 09:04
  • I use replace(/\s/g, '') in order to be able to do some calculations with the amount. After this, I need to "format" to better showing the results to users. – Cutis May 07 '19 at 09:06

1 Answers1

0

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
     <script>
         var num = 84000000;
         let strr = num.toLocaleString('fr-FR');
         let output=""
            for(i=0;i<strr.length;i++){
              if(strr[i].charCodeAt(0) == 8239)
                output+=" ";
               else output+=strr[i]
            }
            console.log(output);
            $('body').text(output); 

        </script>
Shiva
  • 476
  • 3
  • 15