问题
I am using these codes to create a table in derby database.
CREATE TABLE "USED_BANKACCOUNT"
(
"FYEAR" VARCHAR(10),
"NUM" DOUBLE,
"USERNAME" VARCHAR(20)
);
My data is stored like this.
FYEAR NUM USERNAME
---------------------------------------------------
2013 10.5 Pranjal
2013 5.25 Pranjal
2013 9.0 Bimal
---------------------------------------------------
But I want my data to be stored like this
FYEAR NUM USERNAME
---------------------------------------------------
2013 10.50 Pranjal
2013 5.25 Pranjal
2013 9.00 Bimal
---------------------------------------------------
What should I do with my DOUBLE
datatype ?
回答1:
Use a DECIMAL type with a defined precision and scale:
CREATE TABLE "USED_BANKACCOUNT" (
"FYEAR" VARCHAR(10),
"NUM" DECIMAL(5, 2),
"USERNAME" VARCHAR(20)
);
The precision
represents the total number of digits allowed in the number(both to the left and the right of the decimal poin), and the scale
represents the number of fractional digits allowed. So the above example defines a decimal number that will allow a maximum of 5 digits, with 2 digits in the fractional component.
来源:https://stackoverflow.com/questions/16014629/how-can-i-set-up-precision-in-a-double-column-in-derby-database