如何在Derby数据库的双列中设置精度? [英] How can I set up precision in a double column in Derby database?
问题描述
我正在使用这些代码在derby数据库中创建一个表.
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
---------------------------------------------------
我应该如何处理 DOUBLE
数据类型?
What should I do with my DOUBLE
datatype ?
推荐答案
使用DECIMAL 类型:
Use a DECIMAL type with a defined precision and scale:
CREATE TABLE "USED_BANKACCOUNT" (
"FYEAR" VARCHAR(10),
"NUM" DECIMAL(5, 2),
"USERNAME" VARCHAR(20)
);
precision
表示数字中所允许的总位数(小数点的左侧和右侧),而 scale
则表示数字的位数允许的小数位数.因此,上面的示例定义了一个十进制数字,该数字最多允许5位数字,而小数部分为2位数字.
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.
这篇关于如何在Derby数据库的双列中设置精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!