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;
精彩评论