问题:
- 输入的浮点数与小数位,
- input output
- ------- ---------
- 0.123 0.12
- .123 0.12
- .1 0.10
- .199 0.20
- 123.199 123.1990
- create table test_t(
- col_1 number(3,2),
- col_2 number(7,4)
- );
- insert into test_t(col_1) values(0.123);
- insert into test_t(col_1) values(.123);
- insert into test_t(col_1) values(.1);
- insert into test_t(col_1) values(.199);
- insert into test_t(col_2) values(123.199);
- //
- 1.直接查询数据,就能显示效果
- x number(p,s):
- p:x的有效位数,既x的宽度
- s:x的小数位数
- x的有效位数计算:
- s>=0,x的有效位:p
- s<0,x的有效位:p+|s|
- select * from test_t;
- COL_1 COL_2
- ----- ---------
- 0.12 /*因为小数点只是2位,在进行存储时进行了四舍五入*/
- 0.12 /*因为小数点只是2位,在进行存储时进行了四舍五入,当整数部分空缺时,在数据最左边补齐一个0*/
- 0.10 /*当实际值的小数位数小于指定位数时,在数字最右边补齐0*/
- 0.20 /*存储时进行了四舍五入*/
- 123.1990
- //
- 2.使用to_char()函数格式输出
- SQL> select nvl(to_char(col_1,990.99),'Unknow') col_1,
- 2 nvl(to_char(col_2,990.9999),'Unknow') col_2
- 3 from test_t;
- COL_1 COL_2
- ------- ---------
- 0.12 Unknow
- 0.12 Unknow
- 0.10 Unknow
- 0.20 Unknow
- Unknow 123.1990