Double data format sent to mysql

0

My question is this:

For example, enter the number "1" in a JTextField , then, before sending the number to the database and make the corresponding Insert, pass the number to double, and the number in the database is entered as entered in the JTextField (1), and not (1.0). The type of data in my database is float. I have tried in many ways and I still can not get it.

I've tried with:

Double.valueOf(JTextField.getText());

And also with:

Double.parseDouble(JTextField.getText());

I have also tried a lot of validations and it does not validate me either.

    
asked by GinoGiovanni 21.06.2016 в 06:19
source

2 answers

1

In the database, to save decimal numbers, you have to use the type decimal(x,y) where:

x = Amount of Numbers to save y = Number of decimals to save

It is important to note that if, for example, we define a field how decimal(18,2) means that you will have 16 number positions to the left of the comma and 2 decimal places to the right of the comma.

It is also important to analyze really what kind of numbers are going to be saved to try to limit the (x,y) to the maximum.

For what you say, you have defined it as Decimal(4,1) ; is means that your maximum value will be 999.9 (total = 4 positions, 3 left, 1 right).

    
answered by 21.06.2016 / 09:07
source
1

I already found the solution, and it was in the field of the database Change from float to DEC (4,1)

    
answered by 21.06.2016 в 07:22