Skip to content

Commit

Permalink
Manage currency whose subunit is not 100 (like JPY)
Browse files Browse the repository at this point in the history
[Fixes #2030]
  • Loading branch information
kei-s authored and radar committed Oct 2, 2012
1 parent 76b7954 commit ab3db52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/lib/spree/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Spree
class Money
def initialize(amount, options={})
@money = ::Money.new(amount * 100, Spree::Config[:currency])
@money = ::Money.parse([amount, Spree::Config[:currency]].join)
@options = {}
@options[:with_currency] = true if Spree::Config[:display_currency]
@options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym
Expand Down
16 changes: 16 additions & 0 deletions core/spec/lib/money_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#encoding: UTF-8
require 'spec_helper'

module Spree
Expand Down Expand Up @@ -45,5 +46,20 @@ module Spree
money.to_s.should == "10.00 $"
end
end

context "JPY" do
before do
reset_spree_preferences do |config|
config.currency = "JPY"
config.currency_symbol_position = :before
config.display_currency = false
end
end

it "formats correctly" do
money = Spree::Money.new(1000)
money.to_s.should == "¥1,000"
end
end
end
end

0 comments on commit ab3db52

Please sign in to comment.