-
-
Save bjeanes/2587036 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
window.app = format: {} | |
app.format.DollarizesCents = -> | |
dollarize: (pennies) -> | |
amount = (pennies / 100.0).toFixed(2) | |
"$#{@commasFor(amount)}" | |
#private | |
commasFor: (dollars) -> | |
dollars.replace /\d(?=(\d{3})+(\.|$))/g, "$&," |
This file contains hidden or 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
describe "app.format.DollarizesCents", -> | |
Given -> @subject = app.format.DollarizesCents() | |
describe "#dollarize", -> | |
context "0 cents", -> | |
Then -> @subject.dollarize(0) == "$0.00" | |
context "50 cents", -> | |
Then -> @subject.dollarize(50) == "$0.50" | |
context "1,841,482 cents", -> | |
Then -> @subject.dollarize(1841482) == "$18,414.82" | |
context "213,981,400 cents", -> | |
Then -> @subject.dollarize(213981400) == "$2,139,814.00" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment