网上到处都有 function NumToChnStr(Value:Real;ClearZero:Boolean): String; const ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟'); ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); var I: Integer; StrValue, StrNum: String; ValueLen: Integer; begin if Value <= 0 then begin Result := '输入参数应大于零。'; Exit; end; StrValue := IntToStr(Round(Value * 100)); ValueLen := Length(StrValue); Result := ''; for I := 1 to ValueLen do begin StrNum := StrValue[I]; Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I]; end; if ClearZero then begin Result := StringReplace(Result, '零分', '', [rfReplaceAll]); Result := StringReplace(Result, '零角', '', [rfReplaceAll]); Result := StringReplace(Result, '零圆', '圆', [rfReplaceAll]); Result := StringReplace(Result, '零拾', '', [rfReplaceAll]); Result := StringReplace(Result, '零佰', '', [rfReplaceAll]); Result := StringReplace(Result, '零仟', '', [rfReplaceAll]); Result := StringReplace(Result, '零万', '万', [rfReplaceAll]); end; end;
function NumToChnStr(Value:Real;ClearZero:Boolean): String; const ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟'); ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); var I: Integer; StrValue, StrNum: String; ValueLen: Integer; begin if Value <= 0 then begin Result := '输入参数应大于零。'; Exit; end; StrValue := IntToStr(Round(Value * 100)); ValueLen := Length(StrValue); Result := ''; for I := 1 to ValueLen do begin StrNum := StrValue[I]; Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I]; end; if ClearZero then begin Result := StringReplace(Result, '零分', '', [rfReplaceAll]); Result := StringReplace(Result, '零角', '', [rfReplaceAll]); Result := StringReplace(Result, '零圆', '圆', [rfReplaceAll]); Result := StringReplace(Result, '零拾', '', [rfReplaceAll]); Result := StringReplace(Result, '零佰', '', [rfReplaceAll]); Result := StringReplace(Result, '零仟', '', [rfReplaceAll]); Result := StringReplace(Result, '零万', '万', [rfReplaceAll]); end; end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9','.']) then begin key:= #0; end; end;procedure TForm1.Edit1Change(Sender: TObject); begin edit2.Text:= NumToChnStr(StrToFloat(edit1.Text),true); end;
function NumToChnStr(Value:Real;ClearZero:Boolean): String;
const
ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟');
ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
var
I: Integer;
StrValue, StrNum: String;
ValueLen: Integer;
begin
if Value <= 0 then
begin
Result := '输入参数应大于零。';
Exit;
end;
StrValue := IntToStr(Round(Value * 100));
ValueLen := Length(StrValue);
Result := '';
for I := 1 to ValueLen do
begin
StrNum := StrValue[I];
Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
end;
if ClearZero then
begin
Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
Result := StringReplace(Result, '零圆', '圆', [rfReplaceAll]);
Result := StringReplace(Result, '零拾', '', [rfReplaceAll]);
Result := StringReplace(Result, '零佰', '', [rfReplaceAll]);
Result := StringReplace(Result, '零仟', '', [rfReplaceAll]);
Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
end;
end;
function NumToChnStr(Value:Real;ClearZero:Boolean): String;
const
ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟');
ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
var
I: Integer;
StrValue, StrNum: String;
ValueLen: Integer;
begin
if Value <= 0 then
begin
Result := '输入参数应大于零。';
Exit;
end;
StrValue := IntToStr(Round(Value * 100));
ValueLen := Length(StrValue);
Result := '';
for I := 1 to ValueLen do
begin
StrNum := StrValue[I];
Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
end;
if ClearZero then
begin
Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
Result := StringReplace(Result, '零圆', '圆', [rfReplaceAll]);
Result := StringReplace(Result, '零拾', '', [rfReplaceAll]);
Result := StringReplace(Result, '零佰', '', [rfReplaceAll]);
Result := StringReplace(Result, '零仟', '', [rfReplaceAll]);
Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
end;
end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.']) then
begin
key:= #0;
end;
end;procedure TForm1.Edit1Change(Sender: TObject);
begin
edit2.Text:= NumToChnStr(StrToFloat(edit1.Text),true);
end;