3 messages in com.mysql.lists.javaSUMMARY: Storing/retrieving Double.MA...
FromSent OnAttachments
Christophe DIARRA12 Nov 2002 01:16 
Jon Frisby15 Nov 2002 02:43 
Christophe DIARRA15 Nov 2002 05:42 
Subject:SUMMARY: Storing/retrieving Double.MAX_VALUE, Double.MIN_VALUE
From:Christophe DIARRA (dia@ipno.in2p3.fr)
Date:11/15/2002 05:42:08 AM
List:com.mysql.lists.java

Hi.

I have got only one answer (from OUADIO KOYOSSOU SILVERE AFFIAN <2000@ctech.ac.za>). The suggestion is to use varchar type to store such very long/big numbers to avoid rounding and truncation.

My follwing resques is appended bellow.

Christophe.

Hi.

I have to store in a database, data from an other program. The data are in text files and contain sometime java Double.MAX_VALUE and/or Double.MIN_VALUE. My program have also to restore backp the text files from the database. When I restore Double.MAX_VALUE and Double.MIN_VALUE I have 'Infinity' or '-Infinity' because mysql "rounds" the values before storing them: the rounded values are out of the java doubles range.

I use MySQL server 4.0.3-beta-max.

I have not found the solution of my problem on the mailing-lis archive.

Following is a small example demonstrating the problem:

mysql> create table double_test (d double); mysql> insert into double_test values(1.7976931348623157E308); mysql> insert into double_test values(0.10012210012209899); mysql> select * from double_test; +-----------------------+ | d | +-----------------------+ | 1.79769313486232e+308 | ==> becomes bigger than Double.MAX_VALUE | 0.100122100122099 | ==> truncation happened +-----------------------+

The numbers are truncated and rounded. Why and how to avoid it ? I would like store and retrieve the double values without modification.

In my Java program when I read back the data, 1.79769313486232e+308 is considered as 'Infinity' because after the truncation and rounding, the value becomes bigger than the maximum double value allowed (1.7976931348623157E308 under Java).

When I use double(M,D) instead of double in the table creation, the insertion of 1.7976931348623157E308 leads to the value 'inf' when I read back the value by typing 'select * from double_test').

Any idea or experience to share.