Coder Social home page Coder Social logo

thegeekexplorer / gtin-validation Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 5.0 47 KB

Barcode/EAN Validation for GTIN-8, GTIN-12, GTIN-13, and GTIN-14 in Java, PHP, JS, Ruby, TSQL, GO, and VB/VBA

PHP 14.65% JavaScript 10.50% Go 12.25% Ruby 10.08% TSQL 6.09% Java 11.19% VBA 21.65% Swift 13.59%

gtin-validation's People

Contributors

5teev avatar thegeekexplorer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gtin-validation's Issues

License File

Hi There, what license is this code under? It would be helpful for code re-use if you selected a license such as MIT.

Wrong checksum calculation in Swift

Hi,

There are 2 issues with the validation in the Swift version of the algorithm.

First:

  • there are GTINs with also 17 and 18 digits. Currently you only check for 8, 12, 13 and 14.

Second:

  • The calculation of the checkSumDigit like (let checkSumDigit = 10 - checkSum % 10) is wrong when you have checkSum 0.
    You can simply divide the result to %10, if you want to work with the reminder like:
    let checkSumDigit = (10 - checkSum % 10) % 10

or do something more complex, but exactly what you write in the comment by finding the first bigger number and subtracting from it like:
let nextMultipleOf10 = Int(ceil(Float(checkSum) / 10)) * 10
let checkSumDigit = nextMultipleOf10 - checkSum

You can check this with GTIN with checkSum 0 like: 7630872279104

Best regards,
Archangel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.