I am making a table that is pulling data dynamically from a JSON file and I need to be able to change the value to be at two decimal places. Is this even possible based on the code I already have? Examples of what I want to do:
--7 changes to 7.00
--3922.2 changes to 3922.20
--89.2823 changes to 89.28
Thanks so much in advance!
Here is my HTML:
<table id="reportTable" class="reportTable">
<th>Timer Name</th>
<th>Daily Percentile 90th</th>
<th>Daily Percentile 50th</th>
<th>Min Percentile 90th</th>
<th>Max Percentile 90th</th>
<th>Daily Average</th>
</table>
Here is my JQuery and Javascript:
//THIS CODE GETS THE JSON, ALPHABETIZES THE INFO, AND POPULATES THE TABLE.
var information = $.ajax({
type: "GET",
url: "http://websiteIgetmyJSONfrom.com",
dataType: "json",
success: function (information) {
information.sort( function( a, b ) {
a = a.timerName.toLowerCase();
b = b.timerName.toLowerCase();
return a < b ? -1 : a > b ? 1 : 0;
});
$.each(information, function(i, item) {
var $tr = $('<tr class="clickable">').append(
$('<td align="left">').text(item.timerName),
$('<td>').text(item.daily_percentile_90th),
$('<td>').text(item.daily_percentile_50th),
$('<td>').text(item.min_percentile_90th),
$('<td>').text(item.max_percentile_90th),
$('<td>').text(item.daily_average)).appendTo('#reportTable');
});
},
error: function(){ alert("FAILED TO LOAD JSON"); }
});
Example of JSON returned:
{
"daily_percentile_90th": 4430.6,
"min_percentile_90th": 1598.8,
"max_percentile_90th": 5518.9,
"daily_percentile_50th": 3793.5,
"timerName": "Temple:Shared",
"daily_average": 3745.16
},
{
"daily_percentile_90th": 1904.2,
"min_percentile_90th": 634.4,
"max_percentile_90th": 3296.6,
"daily_percentile_50th": 1103.5,
"timerName": "Search:Catalog",
"daily_average": 1332.82
},
{
"daily_percentile_90th": 780,
"min_percentile_90th": 0.8,
"max_percentile_90th": 780,
"daily_percentile_50th": 239,
"timerName": "FT:Person:Ordinances",
"daily_average": 397.324
},