Content deleted Content added
→Example for validating check digit: html math |
Tag: Reverted |
||
Line 9:
The check digit is computed as follows:
# If the number already contains the check digit, drop that digit to form the "payload". The check digit is most often the last digit.
# With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit). If you start from the leftmost digit (like below code) even lengh payload doubles the odd positions and odd lenght payload doubles the even positions.
# Sum the values of the resulting digits.
# The check digit is calculated by <math>(10 - (s \operatorname{mod} 10)) \operatorname{mod} 10</math>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <math>s</math> to make a multiple of 10. Other valid formulas giving the same value are <math>9 - ((s + 9)\operatorname{mod} 10)</math>, <math>(10 - s)\operatorname{mod} 10</math>, and <math>10\lceil s/10\rceil - s</math>. Note that the formula <math>(10 - s)\operatorname{mod} 10</math> will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation.
|