- 论坛徽章:
- 0
|
#---------------------------------------------------------------------#
# -- 將一串數字返回漢字大寫 -- zwx
# -- Ssta='S',簡短型 50010.00 伍萬 零 壹拾 圓 零角 零分)
# -- Ssta='L',完整型 50010.00 伍萬 零仟 零佰 壹拾 零圓 零角 零分)
#---------------------------------------------------------------------#
FUNCTION num_to_upcode(Snum,Ssta)
DEFINE Snum DEC(16,2),
Ssta CHAR(1),
S1str CHAR(20),
S3str CHAR(2),
Snstr CHAR(100),
Srstr CHAR(100),
Slen INT,
Scnt INT,
St1 INT,
St2 INT,
St3 INT
LET S1str = Snum
# display 'Input:',Snum,' -- >',S1str
LET Slen = LENGTH(S1str)
FOR St1 = 1 TO Slen
IF S1str[St1] = '.' THEN
EXIT FOR
END IF
END FOR
LET Snstr = NULL
LET S3str = ' '
FOR St2 = 1 TO Slen
LET St3 = St1 - St2
LET S3str = ' '
CALL num_1to_upcode(S1str[St2]) RETURNING S3str
LET Snstr = Snstr CLIPPED,S3str CLIPPED
LET Snstr = Snstr CLIPPED
LET Scnt = LENGTH(Snstr)
IF Scnt > 4 THEN
IF Snstr[Scnt-3,Scnt] = '零零' THEN
LET Snstr[Scnt-1,Scnt] = ' '
END IF
END IF
IF S1str[st2] = '-' THEN
CONTINUE FOR
END IF
LET S3str = ' '
CALL num_2to_upcode(St3) RETURNING S3str
LET Snstr = Snstr CLIPPED,S3str CLIPPED
IF Ssta = 'S' THEN
LET Snstr = Snstr CLIPPED
LET Scnt = LENGTH(Snstr)
IF Scnt > 4 THEN
IF Snstr[Scnt-3,Scnt] = '零圓' OR
Snstr[Scnt-3,Scnt] = '零萬' OR
Snstr[Scnt-3,Scnt] = '零億' OR
Snstr[Scnt-3,Scnt] = '零兆' THEN
LET Snstr[Scnt-3,Scnt-2] = Snstr[Scnt-1,Scnt]
LET Snstr[Scnt-1,Scnt] = ' '
END IF
END IF
LET Snstr = Snstr CLIPPED
LET Scnt = LENGTH(Snstr)
IF Scnt > 4 THEN
IF Snstr[Scnt-3,Scnt] = '兆億' OR
Snstr[Scnt-3,Scnt] = '兆萬' OR
Snstr[Scnt-3,Scnt] = '零拾' OR
Snstr[Scnt-3,Scnt] = '零佰' OR
Snstr[Scnt-3,Scnt] = '零仟' OR
Snstr[Scnt-3,Scnt] = '億萬' THEN
LET Snstr[Scnt-1,Scnt] = '零'
END IF
END IF
END IF
LET Snstr = Snstr CLIPPED
LET Scnt = LENGTH(Snstr)
IF Scnt > 4 THEN
IF Snstr[Scnt-3,Scnt] = '零零' THEN
LET Snstr[Scnt-1,Scnt] = ' '
END IF
END IF
END FOR
# display 'Output:-- >',Snstr
# -- 格式調整,加空格
LET Srstr = "("
LET Snstr = Snstr CLIPPED
LET Slen = LENGTH(Snstr)
FOR St2 = 1 TO Slen/2
LET St1 = St2 * 2
LET S3str = Snstr[St1-1,St1]
IF S3str MATCHES '[負兆億萬仟佰拾圓角]' THEN
LET Srstr = Srstr CLIPPED,S3str,'_'
ELSE
IF S3str MATCHES '[零]' AND St2 <= Slen/2-4 AND
Ssta = 'S' THEN
LET Srstr = Srstr CLIPPED
LET Scnt = LENGTH(Srstr)
IF Srstr[Scnt] = '_' THEN
LET Srstr = Srstr CLIPPED,S3str,'_'
ELSE
LET Srstr = Srstr CLIPPED,'_',S3str,'_'
END IF
ELSE
LET Srstr = Srstr CLIPPED,S3str
END IF
END IF
END FOR
LET Srstr = Srstr CLIPPED,')'
LET Srstr = Srstr CLIPPED
LET Slen = LENGTH(Srstr)
FOR St2 = 1 TO Slen
IF Srstr[St2] = '_' THEN
LET Srstr[St2] = ' '
END IF
END FOR
# display 'Return:-- >',Srstr
RETURN Srstr
END FUNCTION
#---------------------------------------------------------------------#
# -- 將一個數字返回漢字名稱 -- zwx
#---------------------------------------------------------------------#
FUNCTION num_1to_upcode(Snum)
DEFINE Snum CHAR(1),
Sstr CHAR(2)
LET Sstr = ' '
CASE
WHEN Snum = '-'
LET Sstr = '負'
WHEN Snum = '0'
LET Sstr = '零'
WHEN Snum = '1'
LET Sstr = '壹'
WHEN Snum = '2'
LET Sstr = '貳'
WHEN Snum = '3'
LET Sstr = '參'
WHEN Snum = '4'
LET Sstr = '肆'
WHEN Snum = '5'
LET Sstr = '伍'
WHEN Snum = '6'
LET Sstr = '陸'
WHEN Snum = '7'
LET Sstr = '柒'
WHEN Snum = '8'
LET Sstr = '捌'
WHEN Snum = '9'
LET Sstr = '玖'
END CASE
RETURN Sstr
END FUNCTION
#---------------------------------------------------------------------#
# -- 返回數字對應的位數代碼 -- zwx
#---------------------------------------------------------------------#
FUNCTION num_2to_upcode(Snum)
DEFINE Snum INT,
Sstr CHAR(2)
LET Sstr = ' '
CASE
WHEN Snum MOD 4 = 2
LET Sstr = '拾'
WHEN Snum MOD 4 = 3
LET Sstr = '佰'
WHEN Snum MOD 4 = 0 AND Snum > 0
LET Sstr = '仟'
WHEN Snum = 5
LET Sstr = '萬'
WHEN Snum = 9
LET Sstr = '億'
WHEN Snum = 13
LET Sstr = '兆'
WHEN Snum = 0
LET Sstr = '圓'
WHEN Snum = -1
LET Sstr = '角'
WHEN Snum = -2
LET Sstr = '分'
END CASE
RETURN Sstr
END FUNCTION
|
|