From: "Velen" on
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?

Thanks

Velen
From: =?ISO-8859-15?Q?Tobias_Franz=E9n?= on
Velen 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?
>
> Thanks
>
> Velen
>
>
Hello Velen,

Your question seem purely related to MySQL. Not very PHP related. Anyway...

It depends on your version of MySQL. Check the documentation for Numeric
Types. It says you can specify the number of decimals you want to store,
something like FLOAT(max_digits,precision). If you need more precision,
there's also the DOUBLE PRECISION.

If your MySQL column is specified for higher precision already, then it
could be a PHP issue. Is this the case?

For MySQL => 5.0
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

For MySQL < 5.0
http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html


/Tobias
From: "Daniel Brown" on
On Feb 17, 2008 10:59 AM, Velen <velen(a)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 Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>
From: Chris on
Daniel Brown wrote:
> On Feb 17, 2008 10:59 AM, Velen <velen(a)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.

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/