All I need is a simple script that will format a number value (in cents) to a dollar format.
Examples:
599 -> 5.99
2000 -> 20.00
50 -> 0.50
1 -> 0.01
Thanks in advance!![]()
| SitePoint Sponsor |



All I need is a simple script that will format a number value (in cents) to a dollar format.
Examples:
599 -> 5.99
2000 -> 20.00
50 -> 0.50
1 -> 0.01
Thanks in advance!![]()

Well, here's something, its ugly, but I think it works.
Code:<script> function cents(amount){ amount = amount/100; if (Math.floor(amount)==amount){ amount=amount+".00"; } else if (Math.floor(amount*10)==amount*10){ amount=amount+"0"; } return amount; } alert(cents(100)) </script>



Thanks much![]()
Bookmarks