 Former Member

# Calculating Luhn Check Digit

<p>I have an 18 digit number and i need a SQL formula in Crystal Reports to calculate the Luhn digit.</p><p>Below is how Luhn is calculated.</p><p>Step 1: Double the value of alternate digits beginning with the first right hand digit.</p><p>e.g 8 6 3 7 5 = 8 12 3 14 5</p><p>Step 2: Add the individual digits compromising the products obtained in Step 1 to each of the unaffected digits in the original number.</p><p>e.g 8 12 3 14 5 = 8123145 (total=24)</p><p>Step 3: Subtract the total obtained in Step 2 from the next higher number ending in 0.</p><p>e.g 24 = 30-24 = 6 (Luhn = 6!)</p><p>Any help here would be fantastic!!</p>

10|10000 characters needed characters exceeded

### Related questions

• Former Member
Posted on Sep 08, 2006 at 01:44 AM

Is this the same as Mod 10?Â I did some reading on luhn http://en.wikipedia.org/wiki/Luhn_algorithm Â first off this reading says that the luhnÂ calculation is the same as mod 10, in that case you could use "Modulus" in the formula editor of Crystal Reports, under Operators | Arithmatic. However, this gives a different answer to the way you have it calculated. In readingÂ further it seems luhn is used to check validity of a given number that follows a certain set of rules. It says to check validity you divide by 10 and if the result is 0 then the number is valid.
IfÂ I follow the instruction in the link the result would be 5, not equaling 0 would indicate false
Im not a mathmatician nor doÂ I calim to fully understand luhn or mod 10 but it would seem something is out of sync here between how its explained in the link above and your post.
At any rate,Â will the "Modulus" operator work somehow for you?