Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10222 (new defect)

Opened 2 years ago

comma as decimal point causes losing of decimal fraction

Reported by: missaak Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 1.2.3
Severity: normal Keywords:
Cc:

Description

Czech Collation on MS SQL Server 2005 (and maybe on other RDBMS) stores decimal number in following format "xxx,yy" where comma (,) is used as decimal point.

something like this is returned after load of this number from database:

=> #<Amount:0x4b7db40 @attributes={"value"=>"5000,77"}>

And calling method value on returned object causes:

a.value

=> 5000

Problem is that BigDecimal construtor stops their input on unknown character (comma in this case).

When I override instance_variable_set method in model class like this:

  def instance_variable_set symbol, obj
    super
    if symbol == "@attributes"
      input = obj["value"]
      unless input.nil? or input.index(",").nil?
        input[input.index(",")] = "."
        @value = BigDecimal.new(input)
      end
    end
  end

everything is OK. But this is not good solution. I preferred any solution in sqladapter, ActiveBase::Record or BigDecimal working with locales.