DECIMAL成CHAR [英] DECIMAL into CHAR
问题描述
嗨!
让'我们有一个DECIMAL(6,2)类型的数据,值为0.01。
如何转换这个一个成为漂亮的CHAR?
我试过了
VALUES(CHAR(DECIMAL(0.01,6,2)))
我得到了/>
0000.01
不太好。
祝你好运,
Kovi
-
- 〜 - 〜 - 〜 - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - 〜 - 〜 - 〜 - 〜 - 〜 -
|在一个没有围栏需要盖茨的世界里? |
|体验Linux。 |
- 〜 - 〜 - 〜 - 〜 - 〜 - 〜 - ~~~~~~~~~~~~~~~~~~~~~~ 〜 - 〜 - 〜 - 〜 -
Hi!
Let''s have a data of type DECIMAL(6, 2) and with value 0.01.
How can I convert this one into a "pretty" CHAR?
I''ve tried
VALUES(CHAR(DECIMAL(0.01, 6, 2)))
and I get
0000.01
which is not nice.
Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
推荐答案
Gregor Kovac(写道:
Gregor Kovac( wrote:
嗨!
我们有一个类型为DECIMAL(6,2)并且值为0.01的数据。
如何将此数据转换为漂亮CHAR?
我试过了
VALUES(CHAR(DECIMAL(0.01,6,2)))
和我得到了
0000.01
哪个不好。
Hi!
Let''s have a data of type DECIMAL(6, 2) and with value 0.01.
How can I convert this one into a "pretty" CHAR?
I''ve tried
VALUES(CHAR(DECIMAL(0.01, 6, 2)))
and I get
0000.01
which is not nice.
STRIP / TRIM将在DB2中完成你需要的工作9
干杯
Serge
-
Serge Rielau >
DB2解决方案开发
IBM多伦多实验室
WAIUG会议
http://www.iiug.org/waiug/present/Fo...Forum2006.html
我假设DECIMAL presision和scale是任意ch osen。
我无法想象比这更简单。我觉得这种方式太棒了
strightforwards。
我希望有人表现出更优雅的方式。
--------- ---------------------输入的命令
------------------- -----------
VALUES SUBSTR('' - '',1,INT(1-SIGN(SIGN(DECIMAL(0.01,6,2))+ 1) ))
|| SUBSTR(''0'',1,INT(1-SIGN(SIGN(ABS(DECIMAL(0.01,6,2)) - 1)+1)))
|| TRANSLATE(LTRIM(翻译(RTRIM(CHAR(ABS(DECIMAL(0.01,6,
2)))),'''','0' ')),''0'','''');
-------------------------- -------------------------------------------------- -
1
----------
0.01
I assumed DECIMAL presision and scale are arbitrary chosen.
I can''t imagine simpler than this. I feel that this way is too
strightforwards.
I hope someone show more elegant way.
------------------------------ Commands Entered
------------------------------
VALUES SUBSTR(''-'',1,INT(1-SIGN(SIGN(DECIMAL(0.01, 6, 2))+1)))
||SUBSTR(''0'',1,INT(1-SIGN(SIGN(ABS(DECIMAL(0.01, 6, 2))-1)+1)))
||TRANSLATE(LTRIM(TRANSLATE(RTRIM(CHAR(ABS(DECIMAL (0.01, 6,
2)))),'''',''0'')),''0'','' '');
------------------------------------------------------------------------------
1
----------
0.01
如果您只是使用STRIP,小数点前的''0'(''。'')将会丢失。
如果值为负,我想添加前导
减号('' - '')并不是那么简单。
(也许,CASE表达式等是必要的)
------------------------------输入的命令
--------- ---------------------
VALUES STRIP(CHAR(ABS(DECIMAL(0.01,6,2))),L,' '0'');
------------------------------------ ------------------------------------------
1
-----------
..01
1条记录( s)选中。
If you simply used STRIP, ''0'' before decimal point(''.'') will be lost.
And if value is negative, I guess it is not so simple to add leading
minus sign(''-'').
(Perhaps, CASE expression, etc will be necessary)
------------------------------ Commands Entered
------------------------------
VALUES STRIP(CHAR(ABS(DECIMAL(0.01, 6, 2))),L,''0'');
------------------------------------------------------------------------------
1
-----------
..01
1 record(s) selected.
这篇关于DECIMAL成CHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!