Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript ean13 checksum generate

function getLastEan13Digit(ean) { 
  if (!ean || ean.length !== 12) throw new Error('Invalid EAN 13, should have 12 digits'); 
  const multiply = [1, 3]; 
  let total = 0; 
  ean.split('').forEach((letter, index) => { 
    total += parseInt(letter, 10) * multiply[index % 2]; 
  }); 
  const base10Superior = Math.ceil(total / 10) * 10; 
  return base10Superior - total;
}
Source by community.atlassian.com #
 
PREVIOUS NEXT
Tagged: #javascript #checksum #generate
ADD COMMENT
Topic
Name
7+6 =