function FloatToCCurrency(lfCurrency: Extended): string;
const
sCNumber: array['0'..'9'] of string[2] = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
sCUnit: array[0..14] of string[2] = ('万', '仟', '佰', '拾', '亿', '仟', '佰', '拾', '万', '仟', '佰', '拾', '元', '角', '分');
var
lfAbsCur: Extended;
sStr: string;
iCurPos, iBegPos, iLen: Integer;
bZeroAdded: Boolean;
begin
lfAbsCur := Abs(lfCurrency);
if lfAbsCur < 0.01 then
Result := '零'
else if lfAbsCur > 100000000000.00 then
Result := '**'
else
begin
if lfCurrency < 0 then
Result := '负'
else
Result := '';
bZeroAdded := False;
sStr := FormatFloat('#', lfAbsCur * 100);
iLen := Length(sStr);
iBegPos := 15 - iLen;
for iCurPos := iBegPos to 14 do
begin
if (sStr[iCurPos - iBegPos + 1] <> '0') then
begin
if (not bZeroAdded) and (iCurPos > iBegPos) and (sStr[iCurPos - iBegPos] = '0') then
begin
AppendStr(Result, '零');
bZeroAdded := True;
end;
AppendStr(Result, sCNumber[sStr[iCurPos - iBegPos + 1]] + sCUnit[iCurPos]);
bZeroAdded := False;
end
else if ((iCurPos = 4) or (iCurPos = 12)) or ((iCurPos = 8) and ((iLen < 11) or ((iLen >= 11) and (Copy(sStr, iLen - 9, 3) <> '000')))) then
AppendStr(Result, sCUnit[iCurPos]);
end;
if sStr[iLen] = '0' then
AppendStr(Result, '整');
end;
end;
贡献一个函数 Delphi 取大写金额: 123.12 -> 壹百贰拾叁元壹角贰分
最新推荐文章于 2023-12-19 22:37:56 发布
这是一个Delphi函数,用于将小数形式的金额转换为中文大写金额字符串。例如,123.12会被转换为'壹百贰拾叁元壹角贰分'。函数首先处理负数和超出一定范围的数值,然后逐位转换数字并添加相应的中文单位。最后,根据需要添加'整'字。
835

被折叠的 条评论
为什么被折叠?



