title: Ruby BigDecimal and MySQL decimal precision mismatch
body: <p>I'm storing some latitudes and longitudes in a MySQL database using Rails 3.0.3. Here is a part of the migration I used to create the table (note the decimal value with a given precision):</p>
  
  <pre><code>create_table :dummies do |t|
    t.decimal :something, :precision =&gt; 13, :scale =&gt; 10
  end
  </code></pre>
  
  <p>The following RSpec example should illustrate where it's going wrong.</p>
  
  <p>I use a BigDecimal for some calculations and the resulting <code>my_value</code> is a number with a large precision (larger than the one specified in the migration). I store the object in the database and retrieve it again.</p>
  
  <p>Comparing the original value with the database value fails as their precision is not the same so it is no longer the same number:</p>
  
  <pre><code>it 'should be equals before and after save' do
    my_value = BigDecimal('4.123456789') * 5000 # more precise than defined in the migration
    dummy = Dummy.new(:something =&gt; my_value)
    location.save!
    Dummy.first.something.should == dummy.something
  end
  </code></pre>
  
  <p>I understand why this is happening (the precision of the decimal in MySQL != the BigDecimal one) but can anyone tell me how I can limit the precision of the <code>my_value</code> BigDecimal before I write it to the database to make sure it respects the database constraints?</p>
  
  <p>Thanks!</p>