I highly recommend to use: dpkg --compare-version or ruby apt/dpkg which holds the compare-version logic.

E.g. pk/ruby-apt-pkg:
https://github.com/spk/ruby-apt-pkg/blob/master/README.md#using