Posted about 8 years ago. Visible to the public. Linked content.

MySQL 5.6 slightly changes DECIMAL data type

About

A MySQL DECIMAL column is used when it is important to preserve exact precision. It takes two parameters, where precision is the total number of digits and scale the number of digits to the right of the decimal point. A DECIMAL(6,2) column may store numbers up to 9,999.99.

In Rails, a decimal column definition looks like this: t.decimal :amount, :precision => 6, :scale => 2.

Issue

MySQL prior to 5.6 stored leading zeros (0003.1) and +/- characters (+2.1) within the column. However, it would permit storing one extra digit in lieu of a + sign, meaning the example column above would store numbers up to 99,999.99.

Starting with 5.6, MySQL does not store leading zeros nor +/- signs any more and "the hacky extra digit" is not supported any more. See the attached link for details.

Solution

If you were relying on the extra digit, just give the column a higher precision like this (7 for 6):

Copy
ALTER TABLE your_table MODIFY COLUMN your_column DECIMAL(7,2);

Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.

Join our free training event and learn to fix any flaky test suite, even in large legacy applications.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
about 8 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more