We can check whether the number is decimal or not with this. Check if the number has a decimal number ...
So, combining this function, you can use
function roundNumber(num){ return num % 1 != 0 ? num.toFixed(2) : num; }
Or I think the best option would be to use
Math.round(num * 100) / 100
Sarath
source share