View Single Post
Old 02-03-2013, 11:12 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by billboy View Post
that seemed to do the trick , although my formatDollar doesnt seem to be working
Have you tried using your error console? What error messages do you receive? reduce() is not supported by all browsers.

Or try this:-

Code:
<script type="text/javascript">

// works with negative numbers also
function formatNumber(x) {
return x.toFixed(2).split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
}

var num = formatNumber(1234567.8897);
num = "$" + num;
alert (num);

</script>
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 02-03-2013 at 11:28 AM..
Philip M is online now   Reply With Quote