How can I set up precision in a double column in Derby database?

↘锁芯ラ 提交于 2021-01-28 00:23:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!