-1

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/tervo/luhn.pl?N=127753224800013

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

Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
001
  • 62,807
  • 94
  • 230
  • 350

1 Answers1

2

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;
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194