Search code examples
javascriptc#jqplot

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


Im grabbing the data from jqplot chart

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

It's displaying the number as this:

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

Numbers are like this in the arrays:

660056.39
646267.9

How do I stop it from presenting the number with that weird comma, and show the numbers correctly?


Solution

  • What I did was:

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

    Edit:

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

    Turns out the number before the comma was just the x-axis label. Not apart of the number.