字符串不是数字

时间:2015-03-27 14:48:02

标签: crystal-reports padding micr

尝试针对字段运行Mod公式时出现问题。我一直收到错误“字符串不是数字”,到目前为止我还没有能够让ToNumber正确格式化字段。通过添加静态值和已填充的三个字段生成该字段。任何帮助将不胜感激。


合并字段和填充

StringVar strMICR;
StringVar strMICRLINE;


strMICRLINE := Chr(13) & "0603250694";
strMICRLINE := strMICRLINE & Right("000000" & Trim(Split({CUST.C_ID_ALPHA},"-")[1]),6);
strMICRLINE := strMICRLINE & Right("00000000" & ToText({STMT.STMT_NUMBER},0,""),8);
strMICRLINE := strMICRLINE & Right("0000000000" & Replace(ToText({@Total},2,""),".",""),10);


//Uncomment below to test Mod10 Check-digit
//strMICR := mod10("0603250694084469108961440000127874");

//IF NumericText (strMICRLINE) 
//THEN ToNumber (strMICRLINE);

Mod10 (strMICRLINE);

MOD10功能

Function (StringVar input_number)

input_number := replace(input_number, " ", "");

numbervar i := length(input_number);
numbervar sum_val := 0;

stringvar position := "odd";

do (
    if position = "odd" then (
        sum_val := sum_val + 3*tonumber(input_number[i]);
        position := "even" )
    else (
        sum_val := sum_val + tonumber(input_number[i]);
        position := "odd" )
    ;

    i := i-1
)  while i > 0;

numbervar remainder_val := Remainder(sum_val, 10);

numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;

input_number + ToText(check_digit, 0)

1 个答案:

答案 0 :(得分:0)

您尝试在不是数字的字符串上调用toNumber(),因此无法转换。您需要先从字符串中删除所有非数字字符。

//Formula sample to strip non-numeric characters
local stringvar input := "78906-adf0asdf-234";
local stringvar output;
local numbervar i;

for i:=1 to length(input) do
  if numerictext(input[i]) then output:=output&input[i];

output

然后我强烈建议您使用内置的mod函数,而不是自己滚动。

toNumber({@NumericTextOnly}) mod 10