Created
January 31, 2012 03:19
-
-
Save tebriel/1708520 to your computer and use it in GitHub Desktop.
currency!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatCurrency(amount) | |
{ | |
var i = parseFloat(amount); | |
if (isNaN(i)) { i = 0.00; } | |
var minus = ''; | |
if (i < 0) { minus = '-'; } | |
i = Math.abs(i); | |
i = parseInt((i + 0.005) * 100, 10); | |
i = i / 100; | |
s = ''; | |
s += i; | |
if (s.indexOf('.') < 0) { s += '.00'; } | |
if (s.indexOf('.') == (s.length - 2)) { s += '0'; } | |
s = minus + s; | |
return "$" + s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment