database - What do scale and precision mean when specifying a decimal field type in Doctrine 2? -
i'm creating decimal field hold financial figure in doctrine2 symfony2 application.
currently, looks this:
/** * @orm\column(type="decimal") */ protected $rate;
when entered value , said value persisted database, rounded integer. i'm guessing need set precision , scale types field, need explain do?
the doctrine2 documentation says:
precision: precision decimal (exact numeric) column (applies decimal column)
scale: scale decimal (exact numeric) column (applies decimal column)
but doesn't tell me awful lot.
i'm guessing precision number of decimal places round to, assume should 2, scale? scale important figures?
should field declaration this? :-
/** * @orm\column(type="decimal", precision=2, scale=4) */ protected $rate;
doctrine uses types similar sql types. decimal happens fixed precision type (unlike floats).
taken mysql documentation:
in decimal column declaration, precision , scale can (and is) specified; example:
salary decimal(5,2)
in example, 5 precision , 2 scale. precision represents number of important digits stored values, , scale represents number of digits can stored next decimal point.
standard sql requires decimal(5,2) able store value 5 digits , 2 decimals, values can stored in salary column range -999.99 999.99.
database symfony2 orm types doctrine2
No comments:
Post a Comment