开发者

Luhn check digit [closed]

开发者 https://www.devze.com 2023-01-05 00:19 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

I cant seem to figure out what is wrong with my check digit code!

At times, it produces 2 length check digit values

Example

1277531815000110 <-- check digit is double value??????
1277532495000110 <-- check digit is double value???????
1277534649000110 <-- check digit is double value???????
127753185300011 <-- good!
127753208500019 <-- good!

All generated numbers are valid, it can be checked at http://www.ee.unb.ca/cgi-bin/开发者_StackOverflow中文版tervo/luhn.pl?N=127753224800013

CODE: http://dl.dropbox.com/u/678582/Email/GenerateAN.txt


This line's the problem:

CheckSumNumber = (((sum / 10) + 1) * 10) - sum;

That will generate 10 when sum is already a multiple of 10. Basically you're just trying to round up. Here's an easy way of doing it:

CheckSumNumber = (((sum + 9) / 10) * 10) - sum;
0

精彩评论

暂无评论...
验证码 换一张
取 消