Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
always store cents as an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay committed Dec 17, 2010
1 parent fb8f4f2 commit e94152f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/money/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def self.add_rate(from_currency, to_currency, rate)
# @see Money.new_with_dollars
#
def initialize(cents, currency = Money.default_currency, bank = Money.default_bank)
@cents = cents.round
@cents = cents.round.to_i
@currency = Currency.wrap(currency)
@bank = bank
end
Expand Down
7 changes: 7 additions & 0 deletions spec/money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
it "returns the amount of cents passed to the constructor" do
Money.new(200_00, "USD").cents.should == 200_00
end

it "stores cents as an integer regardless of what is passed into the constructor" do
[ Money.new(100), 1.to_money, 1.00.to_money, BigDecimal('1.00').to_money ].each do |m|
m.cents.should == 100
m.cents.should be_an_instance_of(Fixnum)
end
end
end

describe "#dollars" do
Expand Down

0 comments on commit e94152f

Please sign in to comment.