数值有可能有两位小数,数值最长11位,不包括小数点
请高手给来段代码
请高手给来段代码
解决方案 »
- 兄弟们有大问题了!!!站等!!!!!!站等!!!!!!!站等!!!!!!!!站等!!!!!!!!站等!!!!!!!!!!!1
- 跳楼大给分啦!!程序编好了,改了一下名字,第二天运行就不成功了??
- 向高手营救.我做了一个程序是在网格里面输入数据出错.请帮我指点.100分酬谢
- 关于时间日期转换问题??
- 请教以下C语言中的enum如何转换为DELPHI中的形式?
- 请教一个websnap的问题,高手请进!~~~~~~~~~~~~~~~~~~~~~~~~~~
- pcAnywhere操作不能刷新的问题?高手来解救我吧!!
- 将VC的代码转换为Delphi。不够再加
- 怎样模拟键盘操作
- 想名流千古的请进
- delphi程序启动SQL Server2000的数据库自动维护计划
- 如何使用scrollbar控制ScrollBox的水平滚动条?
var
sStr, buf, sPower, buf1: string;
i, j, iPosition, lenth, iTmp: Integer;
flag0: boolean; function Sjoin(var buff: string; sString: string; digit: string; nextdig: string; iPos: Integer): Integer;
var
dig: string; // * 1
flag0: Boolean;
begin
flag0 := True; if digit = '0' then
if nextdig <> '0' then
dig := '零'
else
flag0 := False;
if digit = '1' then
dig := '壹';
if digit = '2' then
dig := '贰';
if digit = '3' then
dig := '叁';
if digit = '4' then
dig := '肆';
if digit = '5' then
dig := '伍';
if digit = '6' then
dig := '陆';
if digit = '7' then
dig := '柒';
if digit = '8' then
dig := '捌';
if digit = '9' then
dig := '玖'; if digit = '0' then
if (flag0 = True) and (iPos <> 0) then
begin
buff := buff + dig;
Result := 2;
end
else
Result := 0
else
begin
buff := buff + dig;
buff := buff + sString;
Result := 4;
end;
end;
begin
if money = 0 then
begin
Result := '零元整';
exit;
end;
iPosition := 0;
buf1 := trim(Format('%12.2f', [money])); lenth := Length(buf1);
buf := ' '; // 16 bit space;
j := 1;
for i := 16 - lenth to 15 do
begin
buf[i] := buf1[j];
j := j + 1;
end; for i := 1 to 15 do
begin
iTmp := ord(buf[i]);
if ((iTmp >= 49) and (iTmp <= 58)) or (chr(iTmp) = ',') then
break;
end;
while i <= 15 do
begin
flag0 := True;
iTmp := 0;
case i - 1 of
0, 4, 8: sPower := '仟';
1, 5, 9: sPower := '佰';
2, 6, 10: sPower := '拾';
3:
begin
sPower := '亿';
if copy(buf, i, 1) = '0' then
begin
sStr := sStr + sPower + '零';
iPosition := iPosition + 2;
iTmp := 1;
end;
end;
7:
begin
sPower := '万';
if copy(buf, i, 1) = '0' then
begin
sStr := sStr + sPower + '零';
iPosition := iPosition + 2;
iTmp := 1;
end;
end;
11:
begin
sPower := '元';
if (copy(buf, i, 1) = '0') and (iPosition <> 0) then
begin
sStr := sStr + sPower;
iPosition := iPosition + 2;
iTmp := 1;
end;
end;
12:
begin
flag0 := False;
if (copy(buf, i + 1, 1) = '0') and (copy(buf, i + 2, 1) = '0') then
begin
sPower := '整';
sStr := sStr + sPower;
iPosition := iPosition + 2;
iTmp := 2;
end;
end;
13: sPower := '角';
14:
begin
if copy(buf, i, 1) = '0' then iTmp := 2;
sPower := '分';
end;
end;
if (flag0 = True) and (iTmp = 0) then
begin
if i > 0 then
iPosition := iPosition + Sjoin(sStr, sPower, copy(buf, i, 1), copy(buf, i + 1, 1), iPosition)
else
iPosition := iPosition + Sjoin(sStr, sPower, copy(buf, i, 1), copy(buf, i, 1), iPosition);
end;
if iTmp = 2 then
break
else
i := i + 1;
end;
// If (ilength <> 0) Then ilength := iPosition;
if pos('整', sStr) < 1 then
begin
if (pos('角', sStr) < 1) and (pos('分', sStr) < 1) then
sStr := sStr + '整';
end;
sStr := stringreplace(sStr, '零零', '零', [rfReplaceAll]);
sStr := stringreplace(sStr, '零元', '元', [rfReplaceAll]);
Result := Trim(sStr);
end;
const
cNum: WideString = '零壹贰叁肆伍陆柒捌玖万仟佰拾亿仟佰拾万仟佰拾';
var
i : Integer;
sNum,sTemp,sDecimal: WideString;
str: String;
begin
str :='';
sNum := format('%15d',[round(n)]);
sDecimal := copy(formatfloat('#.############',n),
pos('.',formatfloat('#.############',n))+1,
length(formatfloat('#.############',n))-pos('.',formatfloat('#.############',n)));
sDecimal := format('%15d',[round(StrToFloat(sDecimal))]);
for i := 0 to 14 do
begin
stemp := copy(snum,i+1,1);
if stemp=' ' then continue
else str := str + cNum[strtoint(stemp)+1] + cNum[i+9];
end;
str:=trim(str);
if StrtoFloat(sDecimal)>0 then
begin
str := str +'点';
for i:=0 to 14 do
begin
stemp := copy(sDecimal,i+1,1);
if stemp=' ' then continue
else str := trim(str) + cNum[strtoint(stemp)+1];
end;
end;
Result := str;
end;
//******************************************************************************
// 功能:金额小写转大写
// 名称:sort:string
//******************************************************************************
function NumToChar(const n: Real): string;
const
cNum: WideString = '零壹贰叁肆伍陆柒捌玖--万仟佰拾亿仟佰拾万仟佰拾元角分';
cCha:array[0..1, 0..12]of string=
(( '零元','零拾','零佰','零仟','零万','零亿','亿万','零零零','零零','零万','零亿','亿万','零元'),
( '元','零','零','零','万','亿','亿','零','零','万','亿','亿','元'));
var
i : Integer;
sNum,sTemp : WideString;
begin
result :='';
sNum := format('%15d',[round(n * 100)]);
for i := 0 to 14 do
begin
stemp := copy(snum,i+1,1);
if stemp=' ' then continue
else result := result + cNum[strtoint(stemp)+1] + cNum[i+13];
end;
for i:= 0 to 12 do
Result := StringReplace(Result, cCha[0,i], cCha[1,i], [rfReplaceAll]);
if pos('零分',result)=0
then Result := StringReplace(Result, '零角', '零', [rfReplaceAll])
else Result := StringReplace(Result, '零角','整', [rfReplaceAll]);
Result := StringReplace(Result, '零分','', [rfReplaceAll]);
end;