What do scale and precision mean when specifying a decimal field type in Doctrine 2? What do scale and precision mean when specifying a decimal field type in Doctrine 2? symfony symfony

What do scale and precision mean when specifying a decimal field type in Doctrine 2?


Doctrine uses types similar to the SQL types. Decimal happens to be a fixed precision type (unlike floats).

Taken from the MySQL documentation:

In a DECIMAL column declaration, the precision and scale can be (and usually is) specified; for example:

salary DECIMAL(5,2)

In this example, 5 is the precision and 2 is the scale. The precision represents the number of significant digits that are stored for values, and the scale represents the number of digits that can be stored following the decimal point.

Standard SQL requires that DECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in the salary column range from -999.99 to 999.99.


Just a quick note: I had to remove the quotes from the attributes precision and scale, like so:

@ORM\Column(type="decimal", precision=8, scale=2)


@Column(type="decimal", precision=5, scale=2) means 123.45