找一段大小写转换的代码,打印的时候用一个计算字段转换过来就行了。 delphi版的: function SmallToBig(Const Value: Double): string; const SCnNumber = '零壹贰叁肆伍陆柒捌玖'; SCnPower = '拾佰仟'; var V, V1: Double; X: array[0..4] of Integer; //分别表示万亿位、亿位、万位、元位、分位 N, P, I, J: Integer; //内部使用 S: array[0..4] of string; //目标串 B: array[0..4] of Boolean; //是否零前缀 BK, BL: Boolean; begin V := Int(Value); X[4] := Trunc((Value - V) * 100 + 0.5); //分位 X[0] := 0; //万亿位 X[1] := 0; //亿位 X[2] := 0; //万位 X[3] := 0; //元位 I := 3; while (V > 0) and (I >= 0) do begin V1 := Int(V / 10000) * 10000; X[I] := Trunc(V - V1); Dec(I); V := V1 / 10000; end; BL := True; //检查是否全为零 for I := 0 to 4 do if X[I] <> 0 then begin BL := False; Break; end; if BL then Result := '零元整' else begin //先计算整数部分每节的串 for I := 0 to 3 do begin S[I] := ''; if X[I] > 0 then begin B[I] := False; P := 1000; BK := False; //前位为零 BL := False; //未记录过 for J := 0 to 3 do begin N := X[I] div P; //当前位 X[I] := X[I] - N * P; //剩余位 P := P div 10; //幂 if N = 0 then //当前位为零 begin if J = 0 then B[I] := True //如果是最高位 else if BL then //如果未记录过 BK := True; end else begin if BK then S[I] := S[I] + '零'; BL := True; S[I] := S[I] + Copy(SCnNumber, N * 2 + 1, 2); if J < 3 then S[I] := S[I] + Copy(SCnPower, (3 - J) * 2 - 1, 2); BK := False; end; end; end; end; //小数部分 BL := False; if X[4] mod 10 > 0 then S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '分' else begin BL := True; S[4] := ''; end; X[4] := X[4] div 10; if X[4] > 0 then begin S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '角' + S[4]; B[4] := False; end else B[4] := not BL; //合并串 Result := ''; BL := False; for I := 0 to 3 do if Length(S[I]) > 0 then begin if BL then if B[I] then Result := Result + '零'; Result := Result + S[I]; case I of 0, 2: Result := Result + '万'; 1: Result := Result + '亿'; 3: Result := Result + '元'; end; BL := True; end else if BL then case I of 1: Result := Result + '亿'; 3: Result := Result + '元'; end; if Length(S[4]) = 0 then Result := Result + '整' else begin if B[4] then if BL then Result := Result + '零'; Result := Result + S[4]; end; end; end; VB.NET版的: Function Get_Chinese(ByVal m As Double) As String Dim Num_To_Chinese() As String = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"} Dim Pre As Integer Dim Had_Frist_Num As Boolean Dim temp As String = "" Pre = 0 re: Select Case m Case Is >= 10000000 And m < 100000000 Had_Frist_Num = True temp = Num_To_Chinese(Int(m / 10000000)) & "千" Pre = 1 m = m - Int(m / 10000000) * 10000000 GoTo re Case Is >= 1000000 And m < 10000000 Had_Frist_Num = True temp = temp & Num_To_Chinese(Int(m / 1000000)) & "百" Pre = 2 m = m - Int(m / 1000000) * 1000000 GoTo re Case Is >= 100000 And m < 1000000 If Not Had_Frist_Num Then temp = Num_To_Chinese(Int(m / 100000)) & "拾" ElseIf Pre <> 2 Then temp = temp & "零" & Num_To_Chinese(Int(m / 100000)) & "拾" Else temp = temp & Num_To_Chinese(Int(m / 100000)) & "拾" End If Had_Frist_Num = True Pre = 3 m = m - Int(m / 100000) * 100000 GoTo re Case Is >= 10000 And m < 100000 If Not Had_Frist_Num Then temp = Num_To_Chinese(Int(m / 10000)) & "万" ElseIf Pre <> 3 Then temp = temp & "零" & Num_To_Chinese(Int(m / 10000)) & "万" Else temp = temp & Num_To_Chinese(Int(m / 10000)) & "万" End If Had_Frist_Num = True Pre = 4 m = m - Int(m / 10000) * 10000 GoTo re Case Is >= 1000 And m < 10000 If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m / 1000)) & "千" ElseIf Pre <> 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m / 1000)) & "千" Else temp = temp & Num_To_Chinese(Int(m / 1000)) & "千" End If Had_Frist_Num = True Pre = 5 m = m - Int(m / 1000) * 1000 GoTo re Case Is >= 100 And m < 1000 If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m / 100)) & "百" ElseIf Pre <> 4 And Pre < 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m / 100)) & "百" ElseIf Pre <> 5 Then temp = temp & "零" & Num_To_Chinese(Int(m / 100)) & "百" Else temp = temp & Num_To_Chinese(Int(m / 100)) & "百" End If Had_Frist_Num = True Pre = 6 m = m - Int(m / 100) * 100 GoTo re Case Is >= 10 And m < 100 If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m / 10)) & "拾" ElseIf Pre <> 4 And Pre < 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m / 10)) & "拾" ElseIf Pre <> 6 Then temp = temp & "零" & Num_To_Chinese(Int(m / 10)) & "拾 " Else temp = temp & Num_To_Chinese(Int(m / 10)) & "拾" End If Had_Frist_Num = True Pre = 7 m = m - Int(m / 10) * 10 GoTo re Case Is >= 1 And m < 10 If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m)) & "元" ElseIf Pre <> 4 And Pre < 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m)) & "元" ElseIf Pre <> 7 Then temp = temp & "零" & Num_To_Chinese(Int(m)) & "元" Else temp = temp & Num_To_Chinese(Int(m)) & "元" End If Had_Frist_Num = True Pre = 8 m = m - Int(m) GoTo re Case Is >= 0.1 If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m * 10)) & "角" ElseIf Pre <> 4 And Pre < 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m * 10)) & "角" ElseIf Pre <> 8 Then temp = temp & "元零" & Num_To_Chinese(Int(m * 10)) & "角" Else temp = temp & Num_To_Chinese(Int(m * 10)) & "角" End If Pre = 9 m = m - Int(m * 10) / 10 GoTo re Case Is >= 0.01 If m <> 0 Then If Not Had_Frist_Num Then temp = temp & Num_To_Chinese(Int(m * 100)) & "分" ElseIf Pre <> 4 And Pre < 4 Then temp = temp & "万零" & Num_To_Chinese(Int(m * 100)) & "分" ElseIf Pre <> 8 And Pre <> 9 Then temp = temp & "元零" & Num_To_Chinese(Int(m * 100)) & "分" Else temp = temp & Num_To_Chinese(Int(m * 100)) & "分" End If End If Pre = 10 End Select temp = temp.Trim If temp = "" Then temp = "零" End If Get_Chinese = temp End Function
delphi版的:
function SmallToBig(Const Value: Double): string;
const
SCnNumber = '零壹贰叁肆伍陆柒捌玖';
SCnPower = '拾佰仟';
var
V, V1: Double;
X: array[0..4] of Integer; //分别表示万亿位、亿位、万位、元位、分位
N, P, I, J: Integer; //内部使用
S: array[0..4] of string; //目标串
B: array[0..4] of Boolean; //是否零前缀
BK, BL: Boolean;
begin
V := Int(Value);
X[4] := Trunc((Value - V) * 100 + 0.5); //分位
X[0] := 0; //万亿位
X[1] := 0; //亿位
X[2] := 0; //万位
X[3] := 0; //元位
I := 3;
while (V > 0) and (I >= 0) do
begin
V1 := Int(V / 10000) * 10000;
X[I] := Trunc(V - V1);
Dec(I);
V := V1 / 10000;
end;
BL := True; //检查是否全为零
for I := 0 to 4 do
if X[I] <> 0 then
begin
BL := False;
Break;
end;
if BL then
Result := '零元整'
else
begin
//先计算整数部分每节的串
for I := 0 to 3 do
begin
S[I] := '';
if X[I] > 0 then
begin
B[I] := False;
P := 1000;
BK := False; //前位为零
BL := False; //未记录过
for J := 0 to 3 do
begin
N := X[I] div P; //当前位
X[I] := X[I] - N * P; //剩余位
P := P div 10; //幂
if N = 0 then //当前位为零
begin
if J = 0 then
B[I] := True //如果是最高位
else
if BL then //如果未记录过
BK := True;
end
else
begin
if BK then
S[I] := S[I] + '零';
BL := True;
S[I] := S[I] + Copy(SCnNumber, N * 2 + 1, 2);
if J < 3 then
S[I] := S[I] + Copy(SCnPower, (3 - J) * 2 - 1, 2);
BK := False;
end;
end;
end;
end;
//小数部分
BL := False;
if X[4] mod 10 > 0 then
S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '分'
else
begin
BL := True;
S[4] := '';
end;
X[4] := X[4] div 10;
if X[4] > 0 then
begin
S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '角' + S[4];
B[4] := False;
end
else
B[4] := not BL;
//合并串
Result := '';
BL := False;
for I := 0 to 3 do
if Length(S[I]) > 0 then
begin
if BL then
if B[I] then
Result := Result + '零';
Result := Result + S[I];
case I of
0, 2: Result := Result + '万';
1: Result := Result + '亿';
3: Result := Result + '元';
end;
BL := True;
end
else
if BL then
case I of
1: Result := Result + '亿';
3: Result := Result + '元';
end;
if Length(S[4]) = 0 then
Result := Result + '整'
else
begin
if B[4] then
if BL then
Result := Result + '零';
Result := Result + S[4];
end;
end;
end;
VB.NET版的:
Function Get_Chinese(ByVal m As Double) As String
Dim Num_To_Chinese() As String = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}
Dim Pre As Integer
Dim Had_Frist_Num As Boolean
Dim temp As String = ""
Pre = 0
re:
Select Case m
Case Is >= 10000000 And m < 100000000
Had_Frist_Num = True
temp = Num_To_Chinese(Int(m / 10000000)) & "千"
Pre = 1
m = m - Int(m / 10000000) * 10000000
GoTo re
Case Is >= 1000000 And m < 10000000
Had_Frist_Num = True
temp = temp & Num_To_Chinese(Int(m / 1000000)) & "百"
Pre = 2
m = m - Int(m / 1000000) * 1000000
GoTo re
Case Is >= 100000 And m < 1000000
If Not Had_Frist_Num Then
temp = Num_To_Chinese(Int(m / 100000)) & "拾"
ElseIf Pre <> 2 Then
temp = temp & "零" & Num_To_Chinese(Int(m / 100000)) & "拾"
Else
temp = temp & Num_To_Chinese(Int(m / 100000)) & "拾"
End If
Had_Frist_Num = True
Pre = 3
m = m - Int(m / 100000) * 100000
GoTo re
Case Is >= 10000 And m < 100000
If Not Had_Frist_Num Then
temp = Num_To_Chinese(Int(m / 10000)) & "万"
ElseIf Pre <> 3 Then
temp = temp & "零" & Num_To_Chinese(Int(m / 10000)) & "万"
Else
temp = temp & Num_To_Chinese(Int(m / 10000)) & "万"
End If
Had_Frist_Num = True
Pre = 4
m = m - Int(m / 10000) * 10000
GoTo re
Case Is >= 1000 And m < 10000
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m / 1000)) & "千"
ElseIf Pre <> 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m / 1000)) & "千"
Else
temp = temp & Num_To_Chinese(Int(m / 1000)) & "千"
End If Had_Frist_Num = True
Pre = 5
m = m - Int(m / 1000) * 1000
GoTo re Case Is >= 100 And m < 1000
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m / 100)) & "百"
ElseIf Pre <> 4 And Pre < 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m / 100)) & "百"
ElseIf Pre <> 5 Then
temp = temp & "零" & Num_To_Chinese(Int(m / 100)) & "百"
Else
temp = temp & Num_To_Chinese(Int(m / 100)) & "百"
End If
Had_Frist_Num = True
Pre = 6
m = m - Int(m / 100) * 100
GoTo re
Case Is >= 10 And m < 100
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m / 10)) & "拾"
ElseIf Pre <> 4 And Pre < 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m / 10)) & "拾"
ElseIf Pre <> 6 Then
temp = temp & "零" & Num_To_Chinese(Int(m / 10)) & "拾 "
Else
temp = temp & Num_To_Chinese(Int(m / 10)) & "拾"
End If
Had_Frist_Num = True
Pre = 7
m = m - Int(m / 10) * 10
GoTo re
Case Is >= 1 And m < 10
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m)) & "元"
ElseIf Pre <> 4 And Pre < 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m)) & "元"
ElseIf Pre <> 7 Then
temp = temp & "零" & Num_To_Chinese(Int(m)) & "元"
Else
temp = temp & Num_To_Chinese(Int(m)) & "元"
End If
Had_Frist_Num = True
Pre = 8
m = m - Int(m)
GoTo re
Case Is >= 0.1
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m * 10)) & "角"
ElseIf Pre <> 4 And Pre < 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m * 10)) & "角"
ElseIf Pre <> 8 Then
temp = temp & "元零" & Num_To_Chinese(Int(m * 10)) & "角"
Else
temp = temp & Num_To_Chinese(Int(m * 10)) & "角"
End If
Pre = 9
m = m - Int(m * 10) / 10
GoTo re
Case Is >= 0.01
If m <> 0 Then
If Not Had_Frist_Num Then
temp = temp & Num_To_Chinese(Int(m * 100)) & "分"
ElseIf Pre <> 4 And Pre < 4 Then
temp = temp & "万零" & Num_To_Chinese(Int(m * 100)) & "分"
ElseIf Pre <> 8 And Pre <> 9 Then
temp = temp & "元零" & Num_To_Chinese(Int(m * 100)) & "分"
Else
temp = temp & Num_To_Chinese(Int(m * 100)) & "分"
End If
End If
Pre = 10
End Select
temp = temp.Trim
If temp = "" Then
temp = "零"
End If
Get_Chinese = temp
End Function