decimal typecast is wrong if receiving a string #2445

Closed
lunks opened this Issue Aug 6, 2011 · 2 comments

Projects

None yet

1 participant

@lunks
Contributor
lunks commented Aug 6, 2011

If using ActiveRecord with PostgreSQL and SQLite, a column set to decimal stores an incorrect value if it receives a number as a string:

ruby-1.9.3-preview1 :010 > Status.new(:battery_level => "1.1")
 => #<Status id: nil, battery_level: #<BigDecimal:7fd513bc8f50,'0.11E2',9(18)>, created_at: nil, updated_at: nil> 
ruby-1.9.3-preview1 :011 > Status.new(:battery_level => 1.1)
 => #<Status id: nil, battery_level: #<BigDecimal:7fd513b93800,'0.11E1',18(45)>, created_at: nil, updated_at: nil> 

Running with Ruby 1.9.3 and Rails 3-1-stable branch.

Contributor
lunks commented Aug 8, 2011

This also happens in 3.0.9 with Ruby 1.9.2p290.

Contributor
lunks commented Aug 8, 2011

...it happens only when using a different locale which doesn't use dots as the number separator. My mistake. :)

@lunks lunks closed this Aug 8, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment