Home > Archive > PHP DB > February 2008 > Re: [PHP-DB] Help with MySql float
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PHP-DB] Help with MySql float
|
|
| Daniel Brown 2008-02-17, 7:08 pm |
| On Feb 17, 2008 10:59 AM, Velen <velen@biz-mu.com> 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.
--
</Dan>
Daniel P. Brown
Senior Unix G
<? while(1) { $me = $mind--; sleep(86400); } ?>
| |
|
| Daniel Brown wrote:
> On Feb 17, 2008 10:59 AM, Velen <velen@biz-mu.com> wrote:
>
> 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...eric-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/
|
|
|
|
|