...数字的函数。(如中文状态不方便,可以替换为ABCDEFGHIJ)
发布网友
发布时间:2024-10-21 02:12
我来回答
共2个回答
热心网友
时间:2024-11-18 17:28
program fh;
var i:integer;
procedure zh(i:integer);
var ch:char;
begin ch:=ord(i+64);
write('ch');
end;
begin writeln('please input a number');
read(i);
if (i>=0)and(i<=10) then zh(i);
end.
热心网友
时间:2024-11-18 17:26
我有一个用VBA编号中文填写货币的函数,供你参考
Public Function DaXie2(ByVal Num As Double, Optional JinWei As Boolean = True)
'**********************************************
'* 人民币中文大写函数 *
'**********************************************
Dim Str_Wei1, Str_Wei2, Str_Num As String
Dim Str_Yuan, Str_Jiao, Str_Feng As String
Dim Str_RetYuan, Str_RetJiaoFeng As String
Dim Str_Ret1, Str_Ret2 As String
Dim Num_Yuan As Double
Dim Num_Jiao, Num_Feng As Single
Dim Num_i, I As Integer
Str_Wei1 = "拾佰仟"
Str_Wei2 = "万亿万亿万亿"
Str_Num = "壹贰叁肆伍陆柒捌玖"
'范围检测
If Num >= 10 ^ 14 Or Num <= -10 ^ 14 Then
DaXie2 = "#数字超出转换范围!!!#"
Exit Function
End If
'符号检测
If Num < 0 Then
Str_RetYuan = "(负)"
Else
Str_RetYuan = ""
End If
Num = Abs(Num)
'是否“四舍五入”
If JinWei Then
Num = Round(Num, 2) '“四舍五入”
Num_Yuan = Int(Num)
Num_Jiao = Int((Num - Num_Yuan) * 10)
Num_Feng = (Num - Num_Yuan) * 100 - Num_Jiao * 10
Else
Num_Yuan = Int(Num) '舍去最末位
Num_Jiao = Int((Num - Num_Yuan) * 10)
Num_Feng = Int((Num - Num_Yuan) * 100) - Num_Jiao * 10
End If
' ***** 整数部分转换
Str_Yuan = Trim(Str(Format(Num_Yuan, "###0")))
For I = Len(Str_Yuan) To 1 Step -1
Num_i = Val(Mid(Str_Yuan, Len(Str_Yuan) - I + 1, 1)) '第“I”位数
If Num_i <> 0 Then
'非“零”数字转换
Str_RetYuan = Str_RetYuan & Mid(Str_Num, Num_i, 1) ' “I”位数字转换
If (I - 1) Mod 4 <> 0 Then ' “I”位数位转换
Str_RetYuan = Str_RetYuan & Mid(Str_Wei1, (I - 1) Mod 4, 1)
Else
If (I - 1) \ 4 <> 0 Then
Str_RetYuan = Str_RetYuan & Mid(Str_Wei2, (I - 1) \ 4, 1)
End If
End If
Else
'“零”数字转换
If Right(Str_RetYuan, 1) <> "零" Then
'前一位非“零”:本位是“万亿”位加“万、亿”,否则其他加“零”
If (I - 1) Mod 4 <> 0 Then
Str_RetYuan = Str_RetYuan & "零"
Else
If (I - 1) \ 4 <> 0 Then
Str_RetYuan = Str_RetYuan & Mid(Str_Wei2, (I - 1) \ 4, 1)
End If
End If
Else
'前一位也为“零”:本位是“万亿”位加“万、亿”(并删除前面的“零”);其他跳过此位
If (I - 1) Mod 4 = 0 Then
Str_RetYuan = Left(Str_RetYuan, Len(Str_RetYuan) - 1)
If (I - 1) \ 4 <> 0 Then
Str_RetYuan = Str_RetYuan & Mid(Str_Wei2, (I - 1) \ 4, 1)
End If
End If
End If
End If
Next I
If Num_Yuan = 0 Then
Str_RetYuan = ""
Else
Str_RetYuan = Str_RetYuan & "元"
End If
' ***** 小数部分转换
If Num_Jiao <> 0 Then
Str_RetJiaoFeng = Mid(Str_Num, Num_Jiao, 1) & "角"
If Num_Feng <> 0 Then
Str_RetJiaoFeng = Str_RetJiaoFeng & Mid(Str_Num, Num_Feng, 1) & "分"
Else
Str_RetJiaoFeng = Str_RetJiaoFeng & "整"
End If
Else
If Num_Feng <> 0 Then
If Num_Yuan <> 0 Then
Str_RetJiaoFeng = "零" & Mid(Str_Num, Num_Feng, 1) & "分"
Else
Str_RetJiaoFeng = Mid(Str_Num, Num_Feng, 1) & "分"
End If
Else
Str_RetJiaoFeng = Str_RetJiaoFeng & "整"
End If
End If
If Num < 0 Then '返回(包括符号)
DaXie2 = "(负)" & Str_RetYuan & Str_RetJiaoFeng
Else
DaXie2 = Str_RetYuan & Str_RetJiaoFeng
End If
End Function