0

I found this previous post Add comma to numbers every three digits but I can't seem to make it work. I couldn't find the format numbers he listed in the original post, so I used: http://code.google.com/p/jquery-numberformatter/

I also swapped in their example, but it didn't work:

$("#salary").blur(function(){
$(this).parseNumber({format:"#,###.00", locale:"us"});
$(this).formatNumber({format:"#,###.00", locale:"us"});
});

I would like to add the commas to all my "Views" values, I figured that it would be as simple as doing what I did below.

<title>Current Server Stats - ~[date]&nbsp;&nbsp;&nbsp;&nbsp;~[time]</title>
~[wc:commonscripts]
<link href="/images/css/screen.css" rel="stylesheet" media="screen">
<link href="/images/css/print.css" rel="stylesheet" media="print">
<script src="/admin/ps/js/jquery.js"></script>
<script src="/admin/ps/js/jquery.numberformatter.js"></script>

    <script>
    $(document).ready(function() {
        $(".numbers").each(function() {
            $(this).format({format:"#,###", locale:"us"});
        });
    });
    </script>
</head>

Then:

<div class="box-round">

<table border="0" cellspacing="0" cellpadding="4">
<tr bgcolor="#f6f6f6">
<td class="bold">#</td>
<td class="bold">Date</td>
<td class="bold">App Node</td>
<td class="bold">Admin Views</td>
<td class="bold">Teacher Views</td>
<td class="bold">Parent Views</td>
<td class="bold">Student Views</td>
<td class="bold">Hits</td>
<td class="bold">PowerGrade Hits</td>
</tr>

~[tlist_sql;
SELECT
ag.date_value,
r.host_name,
ag.adminpvs,
ag.TeacherPVs,
ag.ParentPVs,
ag.StudentPVs,
ag.hits,
ag.PG3Hits
from aggstats ag
left outer join Server_Instance r on ag.Server_InstanceID = r.id
where date_value=to_date('~[date;dateformat='MM/DD/YYYY']','MM/DD/YYYY')
order by date_value ASC, r.host_name ASC;alternatecolor]
<tr bgcolor="#edf3fe">
<td>~(count;-)</td>
<td>~(ag.date_value;d)</td>
<td>~(r.host_name;t)</td>
<td class="numbers">~(ag.adminpvs;t)</td>
<td class="numbers">~(ag.teacherpvs;t)</td>
<td>~(ag.parentpvs;t)</td>
<td>~(ag.studentpvs;t)</td>
<td>~(ag.hits)</td>
<td>~(ag.PG3hits)</td>

</tr>
[/tlist_sql]
</table>
</div>

1 Answer 1

2

Seems like numberformatter work on input fields or direct on number. But you are trying it on td. Try this

$(document).ready(function() {
    $(".numbers").each(function() {
        var number=$(this).text();
        //alert(number);
        $(this).html($.formatNumber( number,{format:"#,###", locale:"us"}));
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

I replaced what I had between the <script> with that, however it did not add the commas.
remove comments from alert on updated answer and check you are getting number on alert or not. If not make sure tds are available on dom ready.
If you change locale:"us"}); to locale:"us"})); I will mark your answer as correct. Once I did that it started working. Thank you!
Oh... typo mistake.. Fixed it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.