版本一:这种金额大写忽略不同进度间的零的显示,显示效果如:二十万九百一元四角整(200901.40)
StringVar x; StringVar xx :="";
NumberVar z;
NumberVar i;
x := ToText(Sum (
{@@AMOUNT}));
x := Replace(x,",","");
x := Replace(x,".","");
z := length(x)-2;
for i := z to -1 step -1do
(
select i
case10 : if(Mid(x,z-i+1,1) <>"0") then xx := Mid(x,z-i+1,1) +"十"
case9 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"亿"else xx := xx +"亿"
case8 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"仟"
case7 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"佰"
case6 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"拾"
case5 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"万"else xx := xx +"万"
case4 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"仟"
case3 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"佰"
case2 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) +"拾"
case1 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1)+"元"
case0 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1)+"角"
case-1 : if(Mid(x,z-i+1,1) <>"0") then xx := xx + Mid(x,z-i+1,1) else xx :=xx+"零"
);
xx := Replace(xx,"1","壹");
xx := Replace(xx,"2","贰");
xx := Replace(xx,"3","叁");
xx := Replace(xx,"4","肆");
xx := Replace(xx,"5","伍");
xx := Replace(xx,"6","陆");
xx := Replace(xx,"7","柒");
xx := Replace(xx,"8","捌");
xx := Replace(xx,"9","玖");
if instr(xx,'元') <=0 then
if instr(xx,'角')>0 then
xx:=left(xx,instr(xx,'角')-2)+'元'+right(xx,len(xx)-instr(xx,'角')+2);
if right(xx,1)='零' then
if instr(xx,'元')>0 then
xx :=left(xx,len(xx)-1)+'整'
else
xx :=left(xx,len(xx)-1)+'元整'
else
xx :=xx +"分";
版本二:这种金额大写不同进度间的零的显示一次,显示效果如:二十万零九百零一元四角整(200901.40)
StringVar x;
StringVar xx:="";
NumberVar z;
NumberVar i;
x := ToText(Sum ({BuyCompact.SC_SumPrice}));
x := Replace(x,",","");
x := Replace(x,".","");
z := length(x);
for i := z to 1 step -1do
(
StringVar temp:=Mid(x,z-i+1,1);
select i
case12 : xx := temp +"十"
case11 : xx := xx + temp +"亿"
case10 : xx := xx + temp +"仟"
case9 : xx := xx + temp +"佰"
case8 : xx := xx + temp +"拾"
case7 : xx := xx + temp +"万"
case6 : xx := xx + temp +"仟"
case5 : xx := xx + temp +"佰"
case4 : xx := xx + temp +"拾"
case3 : xx := xx + temp +"元"
case2 : xx := xx + temp +"角"
case1 : xx := xx + temp +"分"
);
stringvar test="";
z := length(xx);
i:=1;
while i<z do
(
StringVar temp:=Mid(xx,i,1);
if temp="0" then
(
if mid(xx,i-2,1)<>"0" and (Mid(xx,i+1,1)="亿" or Mid(xx,i+1,1)="万" or Mid(xx,i+1,1)="元") then
(
xx :=Left (xx,i-1 )+Replace(xx,Mid(xx,i,1) ,"" ,i , 1);
)
elseif mid(xx,i-2,1)<>"0" and i+2<length(xx) and mid(xx,i+2,1)<>"0" then
(
xx :=Left (xx,i )+Replace(xx,Mid(xx,i+1,1) ,"" ,i+1 , 1);
)
elseif Mid(xx,i+1,1)="角" and Mid(xx,i+2,1)<>"0" then
(
xx :=Left (xx,i )+Replace(xx,Mid(xx,i+1,1) ,"" ,i+1 , 1);
)
else
(
i := i-1;
xx :=Left (xx,i )+Replace(xx,Mid(xx,i+1,2) ,"" ,i+1 , 1);
)
);
i:=i+1;
z:=length(xx);
);
xx := Replace(xx,"0","零");
xx := Replace(xx,"1","壹");
xx := Replace(xx,"2","贰");
xx := Replace(xx,"3","叁");
xx := Replace(xx,"4","肆");
xx := Replace(xx,"5","伍");
xx := Replace(xx,"6","陆");
xx := Replace(xx,"7","柒");
xx := Replace(xx,"8","捌");
xx := Replace(xx,"9","玖");
xx := xx +"整"+test;
界面代码:
///<summary> /// 大写显示金额
///</summary>
///<param name="value">值</param>
publicvoid UpperAccount(decimal value)
{
if (value ==0)
return;
string strValue = value.ToString();
if (!strValue.Contains("."))
{
strValue +=".00";
}
string strResult =string.Empty;
int z, i;
strValue = strValue.Replace(".", "");
z = strValue.Length;
for (i = z; i >=1; i--)
{
string temp = strValue.Substring(z - i, 1);
switch (i)
{
case12: strResult += temp +"拾"; break;
case11: strResult += temp +"亿"; break;
case10: strResult += temp +"仟"; break;
case9: strResult += temp +"佰"; break;
case8: strResult += temp +"拾"; break;
case7: strResult += temp +"万"; break;
case6: strResult += temp +"仟"; break;
case5: strResult += temp +"佰"; break;
case4: strResult += temp +"拾"; break;
case3: strResult += temp +"元"; break;
case2: strResult += temp +"角"; break;
case1: strResult += temp +"分"; break;
}
}
z = strResult.Length;
while (i < z)
{
string temp = strResult.Substring(i, 1);
if (temp =="0"&& i ==0)
{
i++;
continue;
}
elseif (temp =="0")
{
if (strResult.Substring(i -2, 1) !="0"&& (strResult.Substring(i +1, 1) =="亿"|| strResult.Substring(i +1, 1) =="万"|| strResult.Substring(i +1, 1) =="元"))
{
strResult = strResult.Remove(i, 1);
}
elseif (strResult.Substring(i -2, 1) !="0"&& i +2< strResult.Length && strResult.Substring(i +2, 1) !="0")
{
strResult = strResult.Remove(i +1, 1);
}
elseif (strResult.Substring(i +1, 1) =="角"&& strResult.Substring(i +2, 1) !="0")
{
strResult = strResult.Remove(i +1, 1);
}
else
{
i--;
strResult = strResult.Remove(i +1, 2);
}
}
i++;
z = strResult.Length;
}
strResult = strResult.Replace("0", "零");
strResult = strResult.Replace("1", "壹");
strResult = strResult.Replace("2", "贰");
strResult = strResult.Replace("3", "叁");
strResult = strResult.Replace("4", "肆");
strResult = strResult.Replace("5", "伍");
strResult = strResult.Replace("6", "陆");
strResult = strResult.Replace("7", "柒");
strResult = strResult.Replace("8", "捌");
strResult = strResult.Replace("9", "玖");
lblAccount.Text = strResult +"整";
}