如何將文字轉成數字?
我找到兩個 Source 可以將文字轉成數字,我僅列出第一個,第二個連結供您參考
Source 1 .Convert Character to Numeric
****************************************************************
* Description.. Convert Charcter to Numeric *
* Program Name. F.CONVERT *
* Author....... Bradley V. Stone *
* BVS/Tools - www.bvstools.com *
****************************************************************
H NOMAIN
****************************************************************
* Prototypes *
****************************************************************
D #CtoN PR 30P 9 Character to Numeric
D PR_Char 32 VALUE
*//////////////////////////////////////////////////////////////*
* (#CtoN) Character to Numeric *
* *
* Use: #CtoN(Character_Representation_of_Number) *
* *
*//////////////////////////////////////////////////////////////*
P #CtoN B EXPORT
*--------------------------------------------------------------*
D #CtoN PI 30P 9
D Char 32 VALUE
*
D DS
D Char1 1
D Num1 1 0 OVERLAY(Char1) INZ
*
D Num S 30P 9
D WrkNum S 30P 0
D Sign S 1 0 INZ(1)
D DecPos S 3 0
D Decimal S 1 INZ('N')
D i S 4 0
D j S 4 0
*--------------------------------------------------------------*
C eval Char = %triml(Char)
C ' ' CHECKR Char j 99
*
C if (not *IN99)
C eval j = %size(Char)
C endif
*
C 1 do j i
C eval Char1 = %subst(Char:i:1)
*
C select
C when (Char1 = '-')
C eval Sign = -1
C when (Char1 = '.')
C eval Decimal = 'Y'
C when (Char1 >= '0') and (Char1 <= '9')
C eval WrkNum = (WrkNum * 10 + Num1)
*
C if (Decimal = 'Y')
C eval DecPos = (DecPos + 1)
C endif
*
C endsl
*
C enddo
*
C eval(h) Num = (WrkNum * Sign / (10 ** DecPos))
C RETURN Num
*--------------------------------------------------------------*
C *PSSR BEGSR
C RETURN 0
C ENDSR
*--------------------------------------------------------------*
P #CtoN E
Source 2. RPG Building Blocks: Converting a Character String to a Numeric Value (B980405)
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期二, 10月 31, 2023
2000-03-02 如何將文字轉成數字?
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言