ainoy31 Posted December 21, 2007 Share Posted December 21, 2007 Hello- I have a script that formats a number with commas such as 888888888 will be 888,888,888. Here is the code: function formatNumber(amount) { var delimiter = ","; var a = amount.split('.',2) var d = a[1]; var i = parseInt(a[0]); if(isNaN(i)) { return ''; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); var n = new String(i); var a = []; while(n.length > 3) { var nn = n.substr(n.length-3); a.unshift(nn); n = n.substr(0,n.length-3); } if(n.length > 0) { a.unshift(n); } n = a.join(delimiter); if(d.length < 1) { amount = n; } else { amount = n + '.' + d; } amount = minus + amount; return amount; } var num = formatNumber(amount); I get the error message that amount.split is not a function. Much appreciation. AM Quote Link to comment https://forums.phpfreaks.com/topic/82684-code-issue/ Share on other sites More sharing options...
BenInBlack Posted December 21, 2007 Share Posted December 21, 2007 amount might be empty or you need to string it var samount = new String(amount) if (samount != '') { var a = samount.split('.',2); ... remainder of code ... } else { alert "Amount empty"; } Quote Link to comment https://forums.phpfreaks.com/topic/82684-code-issue/#findComment-420577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.