{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/22325","labels_url":"https://api.github.com/repos/rails/rails/issues/22325/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/22325/comments","events_url":"https://api.github.com/repos/rails/rails/issues/22325/events","html_url":"https://github.com/rails/rails/issues/22325","id":117516450,"number":22325,"title":"Regression in 4.2.5 re: decimal precision","user":{"login":"jaredbeck","id":380809,"avatar_url":"https://avatars.githubusercontent.com/u/380809?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredbeck","html_url":"https://github.com/jaredbeck","followers_url":"https://api.github.com/users/jaredbeck/followers","following_url":"https://api.github.com/users/jaredbeck/following{/other_user}","gists_url":"https://api.github.com/users/jaredbeck/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredbeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredbeck/subscriptions","organizations_url":"https://api.github.com/users/jaredbeck/orgs","repos_url":"https://api.github.com/users/jaredbeck/repos","events_url":"https://api.github.com/users/jaredbeck/events{/privacy}","received_events_url":"https://api.github.com/users/jaredbeck/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-18T05:33:01Z","updated_at":"2015-11-18T05:48:52Z","closed_at":"2015-11-18T05:48:52Z","body":"The following test passes in 4.2.4, fails in 4.2.5.\r\n\r\nThis issue can be reproduced in sqlite, mysql, and postgres.\r\n\r\nAhh the heartbreak of floating point math :sob:\r\n\r\nThanks for having such an easy-to-use bug reporting template, though! :heart:\r\n\r\n```ruby\r\nbegin\r\n  require 'bundler/inline'\r\nrescue LoadError => e\r\n  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'\r\n  raise e\r\nend\r\n\r\ngemfile(true) do\r\n  source 'https://rubygems.org'\r\n  # Activate the gem you are reporting the issue against.\r\n  gem 'activerecord', '4.2.5'\r\n  gem 'sqlite3'\r\nend\r\n\r\nrequire 'active_record'\r\nrequire 'minitest/autorun'\r\nrequire 'logger'\r\n\r\n# Ensure backward compatibility with Minitest 4\r\nMinitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)\r\n\r\n# This connection will do for database-independent bug reports.\r\nActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')\r\nActiveRecord::Base.logger = Logger.new(STDOUT)\r\n\r\nActiveRecord::Schema.define do\r\n  create_table :posts, force: true do |t|\r\n    t.decimal :ukiyo_e, :precision => 6, :scale => 4\r\n  end\r\nend\r\n\r\nclass Post < ActiveRecord::Base\r\nend\r\n\r\nclass BugTest < Minitest::Test\r\n  def test_the_floating_world\r\n    decimal = 0.12345\r\n    post = Post.create!(ukiyo_e: decimal)\r\n    assert_in_delta post.reload.ukiyo_e, decimal, 0.00001\r\n  end\r\nend\r\n```\r\n\r\nThe above test produces the following output:\r\n\r\n```\r\n  1) Failure:\r\nBugTest#test_the_floating_world [active_record_gem.rb:39]:\r\nExpected |0.1235 - 0.12345| (0.00005) to be <= 1.0e-05.\r\n```"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/157610710","html_url":"https://github.com/rails/rails/issues/22325#issuecomment-157610710","issue_url":"https://api.github.com/repos/rails/rails/issues/22325","id":157610710,"user":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"created_at":"2015-11-18T05:48:52Z","updated_at":"2015-11-18T05:48:52Z","body":"That behavior is correct. If you have a scale of 4 you want only 4 digits in the fractional part. This is why Rails is rounding it to 4 digits in the fractional part. See https://github.com/rails/rails/issues/22006#issuecomment-149686388"}}