DECIMAL types - displaying 0s

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nads1982
Forum Newbie
Posts: 9
Joined: Sat Feb 21, 2004 2:37 pm

DECIMAL types - displaying 0s

Post 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
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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]
Post Reply