Is there anyway to prevent Java from turning my double into exponential value? I am having problem with saving that into my database. It keep telling me that it can not convert my VarChar into numeric.
I do;
amt = oldAmt - amt;
amt = Math.abs(amt);
And put the value in amt like so using setter;
jvd.setDr_amt(amt);
Then generate a query string using a function and it give me;
INSERT INTO jv ( id, dr_amt) VALUES (1, 1.595545786E7);
The datatype in the database for dr_amt is numeric(15, 2)
Anyone?
I’m very much guessing that you do something like this:
Don’t do that for the following reasons:
Write your statement in a way to let JDBC handle data types:
If you absolutely must inline your double value in your SQL string instead of using bind values, try using
BigDecimalto serialise your double, instead:Since you seem to be operating on monetary values, you should change all your doubles to
BigDecimalanyway, asBigDecimalis Java’s best match for SQL’sDECIMALdata type