.toLocaleString('fr-FR')未显示空格数量,但在控制台中工作 [英] .toLocaleString('fr-FR') not showing spaces in amount, but working in console
问题描述
我用PHP显示服务器上的一些价格和数字,并使用法语格式的函数.然后,我想使用Jquery在客户端进行一些计算.我使用.toLocaleString('fr-FR')格式化要显示的结果.它可以在控制台中工作,但不能在DOM中工作.
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.
这是代码:
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);
这是我得到的:
ParseInt或parseFloat,均不能解决问题. 请问我做错了什么? 谢谢
ParseInt or parseFloat, none solves the issue. What am I doing wrong please? Thanks
推荐答案
我终于使用了replace(/\s/g, '')
代替replace(/ /g, '')
但是在DOM中以法语格式显示数字始终无法正常工作.
I finally use replace(/\s/g, '')
instead of replace(/ /g, '')
But showing number in french format in DOM is always not working.
这篇关于.toLocaleString('fr-FR')未显示空格数量,但在控制台中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!