Formatting decimal numbers ... again

Formatting decimal numbers ... again

gregravengregraven Posts: 6Questions: 0Answers: 0
edited December 2012 in DataTables 1.9
I'm reading but not understanding, even though this must be really simple.

I have a data source that contains data that looks like this:

[code]
{
"aaData": [
[
"Wilson Hammertec 17",
"09/01/1993",
3.61,
3.12,
3.43,
3.64,
3.65,
0.00,
0.00,
3.66,
2.97,
3.48
]
]
}
[/code]

I call it with code that looks like this:

[code]




$(document).ready(function () {
$('#playtests').dataTable( {
"bProcessing": true,
"sAjaxSource": '/members/Scripts/playtest.js',
"bAutoWidth": false,
"sPaginationType": "two_button",
"iDisplayLength": 15,
"aoColumnDefs": [
{ "sClass": "center", "aTargets": [ 2,3,4,5,6,7,8,9,10,11 ] }
]
});
});

[/code]

Everything works perfectly. The problem is that in the decimal numbers in the resulting table are "reduced" down -- all the trailing zeros are gone. It's not a huge deal, but it makes the table look odd.

Is there a way of preserving the two-decimal-number format for my numerical columns?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Looks like it is how `createTextNode` works in web-browsers...! Here is a little demo showing DataTables, jQuery and DOM methods all showing the same problem: http://live.datatables.net/ivuseg/edit#javascript,html

    To preserve the content you need to make it into strings. DataTables will still sort it numerically.

    Allan
  • gregravengregraven Posts: 6Questions: 0Answers: 0
    Well that's easy! I'll just reconfigure the export from Excel to JSON. Thanks!
This discussion has been closed.