Re: mysql float data type

2014-12-20 Thread Jan Steinman
 From: Lucio Chiappetti lu...@lambrate.inaf.it
 
 never used DECIMAL nor intend to

Why would you blow off an important feature of any system?

DECIMAL performs infinite precision math, and should be used in ALL 
situations where you don't want rounding errors. It should ALWAYS be your first 
choice for quantities of money, for example.

 If a taxpayer thinks he can cheat safely, he probably will. -- Diogenes
 Jan Steinman, EcoReality Co-op 


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mysql float data type

2014-12-17 Thread Lucio Chiappetti

On Tue, 16 Dec 2014, Hartmut Holzgraefe wrote:

On 16.12.2014 15:16, xiangdongzou wrote:


 Can anyone tell me why 531808.11 has been changed to 531808.12 ?


typical decimal-binary-decimal conversion/rounding error.


never used DECIMAL nor intend to, but the issue is typical of precision 
issues among float (32-bit) and double (64-bit) in ANY programming 
language. Google for IEEE floating point


Some (most) users are unaware that a 32-bit real (REAL*4 for oldtimer 
Fortran users like myself) have about 7 digits of precision, while 64-bit 
(doubles, double precision, REAL*8) get to about 16.


So if a quantity needs high precision (typically this occurs for angular 
quantities where arcseconds are important), use double.


--

Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy)
For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html

Do not like Firefox =29 ?  Get Pale Moon !  http://www.palemoon.org

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mysql float data type

2014-12-17 Thread Patrick Sherrill
We always store as strings to avoid rounding issues and then convert for calcs 
to whatever precision we need. 
Pat...

Sent from my iPhone

 On Dec 17, 2014, at 6:24 AM, Lucio Chiappetti lu...@lambrate.inaf.it wrote:
 
 On Tue, 16 Dec 2014, Hartmut Holzgraefe wrote:
 On 16.12.2014 15:16, xiangdongzou wrote:
 
 Can anyone tell me why 531808.11 has been changed to 531808.12 ?
 
 typical decimal-binary-decimal conversion/rounding error.
 
 never used DECIMAL nor intend to, but the issue is typical of precision 
 issues among float (32-bit) and double (64-bit) in ANY programming language. 
 Google for IEEE floating point
 
 Some (most) users are unaware that a 32-bit real (REAL*4 for oldtimer Fortran 
 users like myself) have about 7 digits of precision, while 64-bit (doubles, 
 double precision, REAL*8) get to about 16.
 
 So if a quantity needs high precision (typically this occurs for angular 
 quantities where arcseconds are important), use double.
 
 -- 
 
 Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy)
 For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html
 
 Do not like Firefox =29 ?  Get Pale Moon !  http://www.palemoon.org
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql
 

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: mysql float data type

2014-12-17 Thread Hartmut Holzgraefe


On 17 December 2014 14:21:40 CET, Patrick Sherrill patr...@michael-clarke.com 
wrote:
We always store as strings to avoid rounding issues and then convert
for calcs to whatever precision we need. 
Pat...

So you'll still be affected by rounding errors during conversion and 
calculation,
two problems you'd avoid when using DECIMAL instead ...
-- 
Hartmut Holzgraefe, Principal Support Engineer (EMEA)
MariaDB Corporation | http://www.mariadb.com/

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



mysql float data type

2014-12-16 Thread xiangdongzou
HI everyone:
  I have created a table as flowing;

create table t1(c1 float(10,2), c3 decimal(10,2)); 

 insert two records

insert into t1 values(531808.11, 9876543.12);

insert into t1 values(531808.81, 9876543.12);

the result is 

mysql select * from t1;
+---++
| c1| c3 |
+---++
| 531808.12 | 9876543.12 |
| 531808.81 | 9876543.12 |
+---++

 Can anyone tell me why 531808.11 has been changed to 531808.12 ?


2014-12-16



I AM AN ORACLE FANS!
Skype:Frank.oracle
Email:xiangdong...@gmail.com
Name:东东堂

Re: mysql float data type

2014-12-16 Thread Hartmut Holzgraefe
On 16.12.2014 15:16, xiangdongzou wrote:

  Can anyone tell me why 531808.11 has been changed to 531808.12 ?

typical decimal-binary-decimal conversion/rounding error.



If you want exact decimals you need to stick with the
DECIMAL type which doesn't have this problem, at the
cost of slower calculations though.

see also:

  http://dev.mysql.com/doc/refman/5.5/en/problems-with-float.html

-- 
Hartmut Holzgraefe, Principal Support Engineer (EMEA)
MariaDB Corporation | http://www.mariadb.com/

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql