I need a javascript function that would take a number, and multiply each of the digits alternately by 2 resp. 1, add the result of the multiplication. Note: If the result of a multiplication is two digit number (i. e. 14), add not 14 but 1 + 4 =5 ). Round up the result of the additions to the next 10th and note the difference between the next 10th and the result of the addition in the check digit.
Always start multiplying the second to last digit (i.e. 14 digit at 15 digit numbers and 15th digit at 16 digit numbers, respectively) by 2 and then alternate, multiplying by 1 and 2 proceeding to the left. Do not start with the first digit and start multiplying by 2.
Below are examples for the calculation for the 15 digit customer number
A 15 digit customer number, the first 14 digits are 99200300435738
2 x 8 = 16, 1 x 3 = 3, 2 x 7 = 14, 1 x 5 = 5, 2 x 3 = 6, 1 x 4 = 4
2 x 0 = 0, 1 x 0 = 0, 2 x 3 = 6, 1 x 0 = 0, 2 x 0 = 0, 1 x 2 = 2,
2 x 9 = 18, 1 x 9 = 9
Add 7+3+5+5+6+4+0+0+6+0+0+2+9+9 = 56
Round up to 60
Subtract 56 from 60 = 4
Therefore the check digit is 4 => 992003004357384
Can anyone help?
Thanks
Kati