Currently, I am using AJAX and JSON to retrieve records.
If the variable contains a value, it displays as expected. However, if the variable "performance" is null, it shows NaN
.
Instead of NaN
, I would like to display a number value such as 00.00
.
Is it possible to achieve this? If so, how can it be done? Thank you.
This is my code:
function emp_month_perf(){
jQuery.ajax({
url: "<?php echo base_url(); ?>grade_tasks/emp_monthly_performance",
data:'',
type:"GET",
dataType: "json",
success:function(data){
var total_month_earn = data.total_earn_point;
var total_month_point = data.total_point;
var performance;
var per_color;
performance = (((total_month_earn)/(total_month_point))*100).toFixed(2);
if(performance>80)
{
per_color = "#33CF53";
}
else if(performance>=60 && performance<=80)
{
per_color = "#E0C533";
}
else
{
per_color = "#E12827";
}
document.getElementById("monthperformance").style.backgroundColor = per_color;
$('#monthperformance').html(performance || '00.00');
},
error:function (){}
});
}
setInterval(emp_month_perf, 300000);