返回列表 发帖

在Crystal Report中写函数将数字转为英文


1.在水晶报表中建立一个转换方法 DecimalToWords

Function (numbervar decimals)
    local stringVar array _smallNumbers := ["ZERO",   "ONE",   "TWO",   "THREE",   "FOUR",   "FIVE",   "SIX",   "SEVEN",   "EIGHT",
        "NINE",   "TEN",   "ELEVEN",   "TWELVE",   "THIRTEEN",   "FOURTEEN",   "FIFTEEN",
        "SIXTEEN",   "SEVENTEEN",   "EIGHTEEN",   "NINETEEN"];
    local stringVar array _tens := ["",   "",   "TWENTY",   "THIRTY",   "FORTY",   "FIFTY",   "SIXTY",   "SEVENTY",   "EIGHTY", "NINETY"];
    local stringVar array _scaleNumers := ["", "THOUSAND", "MILLION", "BILLION" ];
    stringVar combined := _smallNumbers[1];
    if decimals <> 0 then
    (
        numberVar i := 1;
        numberVar array digitGroups := [0,0,0,0];

        for i := 1  to 4 step 1  do
        (
            digitGroups := decimals mod 1000;
            decimals := Int(decimals / 1000);
        );
        stringVar array groupText := ["","","",""];
        for i:=1 to 4 step 1 do
        (
            numberVar hundreds := Int(digitGroups / 100);
            numberVar tensUnits := digitGroups mod 100;
            if hundreds <> 0 then
            (
                groupText := groupText + _smallNumbers[hundreds+1] + " HUNDRED";
                if tensUnits <> 0 then
                    groupText := groupText + " ";
            );         
            numberVar tens := Int(tensUnits / 10);
            numberVar units := tensUnits mod 10;
            if tens >= 2 then
            (
                groupText := groupText + _tens[tens+1];
                if units <> 0 then
                    groupText := groupText + "-" + _smallNumbers[units+1];
            )
            else if tensUnits <> 0 then
                groupText := groupText + _smallNumbers[tensUnits +1]
        );
        combined := groupText[1];
        for i:=2 to 4 step 1 do
        (
            if digitGroups <> 0 then
            (
                stringVar prefix := groupText + " " + _scaleNumers;
                if Length(combined) <> 0 then
                    prefix := prefix+ " ";
                combined := prefix + combined;
             );
        );
    );
    combined;

 

 

2.然后在水晶报表中建一个 公式字段 TotalEg

     DecimalToWords ({#Total})  //其中Total是个汇总字段

 

3.把上一步建的公式字段TotalEg拖到报表需要的位置

 

[此帖子已被 stone 在 2009-6-24 11:58:57 编辑过]

Re:在Crystal Report中写函数将数字转为英文

希望有更详细的程序,可以转换小数点的。

TOP

Re:在Crystal Report中写函数将数字转为英文

这段函数是可以正常使用,但不支持小数位

TOP

Re:在Crystal Report中写函数将数字转为英文

是的,写一个貌似很难。您这有现成的吗?

TOP

返回列表