Money not parsing amounts correctly #230

Closed
danbeaulieu opened this Issue Nov 26, 2012 · 7 comments

Comments

Projects
None yet
3 participants

In all of the below cases I'd expect the cents or values to be 1000000

Seems like a pretty big bug, so I'm leaning toward user error.

1.9.3p194 :031 > "10.000".to_money("EUR")
 => #<Money cents:1000 currency:EUR> 

1.9.3p194 :043 > Money.extract_cents("10.000", Money::Currency.find(:eur))
 => 1000 

1.9.3p194 :049 > "10.000".to_money("EUR")
 => #<Money cents:1000 currency:EUR>

1.9.3p194 :055 > Money.parse("10.000", Money::Currency.find(:eur))
 => #<Money cents:1000 currency:EUR> 

1.9.3p194 :056 > Money.from_string("10.000", Money::Currency.find(:eur))
 => #<Money cents:1000 currency:EUR> 

1.9.3p194 :058 > "10.000 EUR".to_money
 => #<Money cents:1000 currency:EUR> 

1.9.3p194 :060 > 10.000.to_money("EUR")
 => #<Money cents:1000 currency:EUR> 
Owner

semmons99 commented Nov 26, 2012

Is it implied that the "." in "10.000" is a thousands separator?

@semmons99 Yes, according to the library it is

1.9.3p194 :064 > Money::Currency.find(:eur).thousands_separator
 => "." 
Owner

semmons99 commented Nov 26, 2012

So the problem is in the #extract_cents method. Feel like taking a crack at it?

@semmons99 I would, but I've got the usual excuses. Also, it doesn't seem like it's just local to #extract_cents method.

for instance the #to_money method doesn't seem to use parse or extract_cents, so there'd need to be some refactoring to ensure that works as well.

I'll poke at it, but I'd be surprised if I had anything before xmas.

Owner

semmons99 commented Nov 26, 2012

No problem. Anyone else fell free to pick this up.

Member

muxcmux commented Nov 27, 2012

I have a question. Why does the spec pass with no errors if I add this to the core_extension_spec (String#to_money)?

"10,370 EUR".to_money.should == Money.new(1_037, "EUR")
"10.370 EUR".to_money.should == Money.new(1_037_000, "EUR")
Member

muxcmux commented Nov 27, 2012

Nevermind, swapped thousands_separator with decimal_mark :(

@muxcmux muxcmux added a commit to muxcmux/money that referenced this issue Nov 27, 2012

@muxcmux muxcmux define spec and implement parsing currencies with different thousands…
…_separators and decimal_marks. issue #230
e3ef333

muxcmux referenced this issue Nov 27, 2012

Closed

fix for #230 #231

semmons99 closed this Jan 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment