.toLocaleString('fr-FR') not showing spaces in amount, but working in console

↘锁芯ラ 提交于 2019-12-11 09:01:31

问题


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.



来源:https://stackoverflow.com/questions/55948982/tolocalestringfr-fr-not-showing-spaces-in-amount-but-working-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!