自定义一个变量如下: ( {@TotalWithTax} 是要显示成人民币大写金额的变量 )
________________________________________________
Global StringVar Array PreDotUnit;
Global StringVar Array ChineseDollar;
Global StringVar Array ResultPreDot;
Global StringVar Array ResultAftDot;
Global StringVar number := ToText(ToNumber({@TotalWithTax}));
// Kill thousand mark
number := Replace (number, ",", "");
ChineseDollar := ["零","壹","貳","叁","肆","伍","陸","柒","捌","玖"];
PreDotUnit := ["元","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟","兆","拾","佰","仟"];
// Get the numbers before decimal
Local StringVar PreDotNumber := Left (number, InStr (number, ".")-1);
// Get the numbers after decimal
Local StringVar PostDotNumber := Right (number, Length (number) - InStr (number, "."));
// Upper the PreDotNumber
if Length (PreDotNumber) =0 then
Redim ResultPreDot [1]
else
Redim ResultPreDot [Length (PreDotNumber)];
if Length (PreDotNumber) =0 then
ResultPreDot [1] ="1";
Local NumberVar i;
For i := 1 To Length (PreDotNumber) Do
(
ResultPreDot [i] := ChineseDollar [ToNumber (Mid (PreDotNumber, i, 1))+1]
);
Redim ResultAftDot[2];
For i :=1 to 2 Do
(
ResultAftDot [i] := ChineseDollar [ToNumber (Mid (PostDotNumber, i, 1))+1]
);
// Add the Chinese Mark
Local NumberVar i;
Local NumberVar j := 1;
For i := Length (PreDotNumber) To 1 Step -1 Do
(
if ResultPreDot [i] = "零" then
if PreDotUnit [j] = "元" then
ResultPreDot [i] := ResultPreDot [i] + PreDotUnit [j]
else if PreDotUnit [j] = "萬" then
ResultPreDot [i] := PreDotUnit [j]
else if PreDotUnit [j] = "億" then
ResultPreDot [i] := PreDotUnit [j]
else if PreDotUnit [j] = "兆" then
ResultPreDot [i] := PreDotUnit [j]
else
ResultPreDot [i]
else
ResultPreDot [i] := ResultPreDot [i] + PreDotUnit [j];
j := j + 1;
);
// Get the last string
Local NumberVar i;
Local NumberVar j;
Local StringVar Answer;
For i := 1 To Length (PreDotNumber) Do
(
if ResultPreDot [i] = "零" and Left (ResultPreDot [i+1], 1) = "零" then
Answer
else if ResultPreDot [i] = "零元" then
Answer := Answer + "元"
else
Answer := Answer + ResultPreDot [i];
);
if Answer ="" then
if PostDotNumber = "00" then
"零元整"
else
"零元"+ ResultAftDot [1] +"角" + ResultAftDot [2] +"分"
else
if PostDotNumber = "00" then
Answer + "整"
else
Answer + ResultAftDot [1] +"角" + ResultAftDot [2] +"分";