[Valentina] [OFF] Decimal field in mySQL

Marcus Bointon marcus at synchromedia.co.uk
Mon Jan 20 15:32:12 CST 2003


on 20/1/03 14:39, Ruslan Zasukhin at sunshine at public.kherson.ua wrote:

> But I ask not float type but DECIMAL type,
> Which do NOT loose digits.

Oops, sorry.
MySQL docs say:

> DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL]
> An unpacked floating-point number. Behaves like a CHAR column: ``unpacked''
> means the number is stored as a string, using one character for each digit of
> the value. The decimal point and, for negative numbers, the `-' sign, are not
> counted in M (but space for these is reserved). If D is 0, values will have no
> decimal point or fractional part. The maximum range of DECIMAL values is the
> same as for DOUBLE, but the actual range for a given DECIMAL column may be
> constrained by the choice of M and D. If UNSIGNED is specified, negative
> values are disallowed. If D is omitted, the default is 0. If M is omitted, the
> default is 10. Prior to MySQL Version 3.23, the M argument must include the
> space needed for the sign and the decimal point.

So, by default, decimal type fields DO lose precision for the example you
gave, however, that would be self inflicted as you wouldn't expect a field
with zero decimal places to store the decimal places, hence you get 7 as
your answer. If I redefine the fields as decimal(10,1) (instead of
decimal(10,0)), the calculation works as expected.

Marcus
-- 
Marcus Bointon
Synchromedia Limited: Putting you in the picture

marcus at synchromedia.co.uk | http://www.synchromedia.co.uk



More information about the Valentina mailing list