Home > php教程 > php手册 > EAN13,最后一位的算法

EAN13,最后一位的算法

WBOY
Release: 2016-06-07 11:41:46
Original
1407 people have browsed it

(偶数位相加*3+奇数位相加)取个位数
如果个位数不等于0,则为(10 - 个位数)
PHP版本:function EAN13($n){<br>         $n=(string)$n;<br>         $a=(($n[1]+$n[3]+$n[5]+$n[7]+$n[9]+$n[11])*3+$n[0]+$n[2]+$n[4]+$n[6]+$n[8]+$n[10])%10;<br>         $a=$a==0?0:10-$a;<br>         return $n.$a;<br>     }JavaScript版本:function EAN13(n){<br>         var n=n.toString();<br>         var a;<br>         a=((n[1]*1+n[3]*1+n[5]*1+n[7]*1+n[9]*1+n[11]*1)*3+n[0]*1+n[2]*1+n[4]*1+n[6]*1+n[8]*1+n[10]*1)%10;<br>         a=a==0?0:10-a;<br>         return n+a;<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template