Forum Moderators: open

Message Too Old, No Replies

Any way to make MYSQL do NOT remove nulls at the end of number?

         

Samuell

11:25 am on Mar 7, 2008 (gmt 0)



Is that possible?
I mean is it possible to hold in db numbers like 6.780 or 0.30 or 9.00?
Thanks in advance!

ZydoSEO

2:45 pm on Mar 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The zeroes are there in the DB, it's all in how you format the number when you select it out of the DB. Search Google for "MySQL string functions" or something like that.

I believe FORMAT(x,d) is a function that may do the trick.

SELECT FORMAT(6.78,3) would yield '6.780'

FYI: Zeroes on the end of numbers are not NULLs. NULL has a totally different meaning for a DB.

rocknbil

10:14 pm on Mar 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I mean is it possible to hold in db numbers like 6.780 or 0.30 or 9.00?

6.780:
create table test (id int(11) primary key auto_increment, percentage decimal (12,3) default '0.000');

0.30 or 9.00:
create table test (id int(11) primary key auto_increment, percentage decimal (12,2) default '0.00');

Samuell

12:50 pm on Mar 11, 2008 (gmt 0)



thats it! decimal really do the trick, thanks alot!