Page 1 of 1
DECIMAL types - displaying 0s
Posted: Wed Mar 10, 2004 10:37 am
by nads1982
I retreive two values from a table each of mysql type DECIMAL(2,2). I then add these values but if the value is something like $5.50 it just prints $5.5! as these refer to money it is important they show any trailing 0s
thank in advance
Posted: Wed Mar 10, 2004 12:11 pm
by penguinboy
DECIMAL(X,Y)
The X is the length of the number of characters stored, including the '-' negative sign.
Ex: -100.00 is 6 characters long.
Ex: 1000.00 is 6 characters long.
The Y is the number of characters beyond the decimal point.
Ex: -100.00 is 2 characters long.
Ex: -100.000 is 3 characters long.
So for numbers ranging from -999.99 through 9999.99 your colum should be DECIMAL(6,2)
DECIMAL(10,2)
Would be
-9999999.99 through
99999999.99
Posted: Wed Mar 10, 2004 1:07 pm
by Weirdan
and, if you add them using PHP, keep in mind that PHP does not honour MySQL type definitions. To preserve formatting take a look at [php_man]number_format[/php_man]