%DEC 用法总结(Convert to Packed Decimal Format)

时间:2016-03-02 ┊ 阅读:5,900 次 ┊ 标签: 开发 , 编程 , 经验

%DEC (Convert to Packed Decimal Format)
%DEC(numeric or character expression{:precision:decimal places})
%DEC(date time or timestamp expression {:format})

%DEC converts the value of the first parameter to decimal (packed) format.

Numeric or character expression
When the first parameter is a numeric or character expression, the result has precision digits and decimal places decimal positions. The precision and decimal places must be numeric literals, named constants that represent numeric literals, or built-in functions with a numeric value known at compile-time.

Note: %LEN and %DECPOS cannot be used directly for the second and third parameters of %DEC or %DECH, even if the values of %LEN and %DECPOS are constant. See Figure 206 on page 509 for an example using the length and decimal positions of a variable to control %DEC and %DECH.

Parameters precision and decimal places may be omitted if the type of expression is neither float nor character. If these parameters are omitted, the precision and decimal places are taken from the attributes of the numeric expression.
If the parameter is a character expression, the following rules apply:
v The sign is optional. It can be ’+’ or ’-’. It can precede or follow the numeric data.
v The decimal point is optional. It can be either a period or a comma.
v Blanks are allowed anywhere in the data. For example, ’ + 3 ’ is a valid parameter.
v The second and third parameters are required.
v Floating point data, for example ’1.2E6’, is not allowed.
v If invalid numeric data is found, an exception occurs with status code 105.
See %DECHfor examples using %DEC.

Date, time or timestamp expression
When the first parameter is a date time or timestamp expression, the optional format parameter specifies the format of the value returned. The converted decimal value will have the number of digits that a value of that format can have, and zero decimal positions. For example, if the first parameter is a date, and the format is *YMD, the decimal value will have six digits.

If the format parameter is omitted, the format of the first parameter is used. See “DATFMT(fmt{separator})” on page 252 and “TIMFMT(fmt{separator})” on page 262. Format *USA is not allowed with a time expression. If the first parameter is a time value with a time-format of *USA, the second format parameter for %DEC must be specified.

Figure 183 on page 476 shows an example of the %DEC built-in function. %DEC (Convert to Packed Decimal Format)

For more information, see “Conversion Operations” on page 410 or “Built-in Functions” on page 394.

D yyddd S 5S 0
D yyyymmdd S 8P 0
D hhmmss S 6P 0
D numeric S 20S 0
D date S
D inz(D’2003-06-27’) DATFMT(*USA)
D time S T inz(T’09.25.59’)
D timestamp S Z inz(Z’2003-06-27-09.25.59.123456’ /free

// Using the format of the first parameter
numeric = %dec(date); // numeric = 06272003
numeric = %dec(time); // numeric = 092559
numeric = %dec(timestamp); // numeric = 20030627092559123456

// Using the second parameter to specify the result format
yyddd = %dec(date : *jul); // yyddd = 03178
yyyymmdd = %dec(date : *iso); // yyyymmdd = 20030627

Figure 182. Using %DEC to convert dates, times and timestamps to numeric

文章评论

添加新评论

温馨提醒:如果您是第一次在本站留言,需要审核后才能显示哦!

相关文章

Whatsapp只能查看最近三天的聊天记录了怎么办?

Whatsapp只能查看最近三天的聊天记录了怎么办?

今天突然发现电脑上的WhatsApp只能查看最近3天的聊天记录了,显示要查看3天前的记录请到手机上查看。很是吃惊,以前一直是所有记录都自动同步到电脑版的啊,不论换电脑了还是换手机了,聊天记录从来没丢过。 查询一翻也没有找出来原因,怎么也同步不过去。 电脑版app重新安装了,也不行。 有个方法说...
阅读全文>>
ValueError: Error getting directory

ValueError: Error getting directory

ssl证书过期了 明明自动renew的 然后看log已经好久没更新成功了 查半天是当前server不信任远程连接 只能自己改代码 报错: 21-12-17 13:01:11 Generate CSR...amkevin.csr amkevin.csr generated. /home/www...
阅读全文>>
网页路径中的'.'和'..'还有'./'和'../'区别

网页路径中的'.'和'..'还有'./'和'../'区别

. 表示当前目录 .. 表示当前目录的上一级目录。 ./表示当前目录下的某个文件或文件夹,视后面跟着的名字而定 ../表示当前目录上一级目录的文件或文件夹,视后面跟着的名字而定。 例如: 文件夹 a 下面有 文件夹b c 和文件 d。 文件夹b下面有e.php 和文件f。 则e中的 . 表示...
阅读全文>>
Introduction to ILE RPG Activation Groups

Introduction to ILE RPG Activation Groups

Learn how activation groups can help your ILE RPG programs run more efficiently, how to specify the type of group to use, and closing and reclaimin...
阅读全文>>
popup.js怎么和content.js通信?[JQuery]

popup.js怎么和content.js通信?[JQuery]

这两天为了实现一个谷歌浏览器插件功能,研究了半天怎么让插件来改特定网页里的特定字段的值,而这个值又来自popup的网页预先设定,下一步实现动态加载,可以让更多组实现便利。 目的很简单,我们有一个list,需要填到网页的某个字段,当然是好几个,这些值是设定好的,网页系统我们没法改,input想...
阅读全文>>