I have an object MyObject that contains a property MyProp that is sometimes numeric. At the moment, I'm showing the number as text like this:
$('#MyDiv').text(MyObject.MyProp);
I want to add formatting to this number. I can check it's numeric but I'm wondering how to do the number formatting.
if ($.isNumeric(MyObject.MyProp) === false) {
$('#MyDiv').text(MyObject.MyProp);
} else {
var PrettyNumber = MakePrettyNumber(MyObject.MyProp);
$('#MyDiv').text(PrettyNumber);
}
I'm thinking about looping through the length of the number string and adding commas to separate thousands and add a dot for decimal. Is there a better way? One that doesn't require a plug-in?
Thanks.