Re: Help with MySql float

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Brown wrote:
On Feb 17, 2008 10:59 AM, Velen <velen@xxxxxxxxxx> wrote:
Hi Guys,

When inserting a value like 123567.8956 in my table it is rounding it to 2
decimal place.  The field type is set as float.

Can anyone tell me why it's not taking all the decimals? and How to insert
the number with all the decimals?

    That's a MySQL question, not a PHP question, but my guess is that
the column is set as FLOAT(x,2) (where x is any real number).  Try
changing that to FLOAT(10,4).  The first number is everything to the
left of the decimal, while the second is the number of places to count
after the decimal.

Also note that a float type is not guaranteed to come back the same as it goes in (and this will also affect maths operations) - so if you need 4 decimal places, then use decimal or numeric as the data type.

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.


The DECIMAL and NUMERIC data types are used to store exact numeric data values. ..... These types are used to store values for which it is important to preserve exact precision, for example with monetary data.


This is the same in any db, it's not a mysql specific behaviour.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux