为什么用逗号显示的数字是错误的地方?

Why is the Number being Displayed with Comma is wrong place?

我正在从 jqplot 图表中抓取数据

        $('#chart1').bind('jqplotDataHighlight',
            function (ev, seriesIndex, pointIndex, data) {
                $('#info1').html("Day " + ticks[pointIndex] +  " - " + plot1.series[seriesIndex].label + ": $" + data);
            }
        );

它显示的号码是这样的:

Day 6 - Online: ,46267.9
Day 6 - Cheque: ,60056.39

数组中的数字是这样的:

660056.39
646267.9

如何阻止它显示带有奇怪逗号的数字,并正确显示数字?

您可以使用 numeraljs(用于格式化和处理数字的 javascript 库)。然后,您可以根据需要取消格式化或格式化数据。

$('#info1').html("Day " + ticks[pointIndex] + " - " + plot1.series[seriesIndex].label + ": $" + 取消格式化(数据));

我所做的是:

var money1 = String(data).replace(/,/g , '');
var money = money1.replace(/(\d)(?=(\d{3})+\.)/g, ',');

编辑:

 var money1 = String(data).split(",")[1];
 var money = money1.replace(/(\d)(?=(\d{3})+\.)/g, ',');

原来逗号前的数字只是x轴标签。不除数。