concept1483166
concept1483166

Reputation: 39

Add commas to values

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>

Upvotes: 0

Views: 586

Answers (1)

Sudhanshu Yadav
Sudhanshu Yadav

Reputation: 2333

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"}));
    });
});

Upvotes: 2

Related Questions