.toLocaleString('fr-FR') not showing space

2019-08-01 17:29发布

问题:

I display some prices and numbers from server with PHP, using functions to format in french. Then I want to use Jquery to do some calculations client-side. I use .toLocaleString('fr-FR') to format the results to show. It works in console but not in DOM.

Here is the code:

resultat_partiel = 1;

resultat_partiel *= parseFloat($(this).text().replace(/ /g, ''), 10);

console.log(resultat_partiel, resultat_partiel.toLocaleString('fr-FR'));

$('div.resultat_partiel').text(parseFloat(resultat_partiel).toLocaleString('fr-FR'));   

var resultat = 0;
var resultats_partiels = $(this).find('.resultat_partiel');
resultats_partiels.each(function(){
console.log($(this).text(), parseFloat($(this).text(), 10));
resultat += parseFloat($(this).text());
    });
$(tbody).find($('td.resultat')).text(resultat);

Here is what I get:

ParseInt or parseFloat, none solves the issue. What am I doing wrong please? Thanks

回答1:

I finally use replace(/\s/g, '') instead of replace(/ /g, '') But showing number in french format in DOM is always not working.