Rebecca Rebecca - 4 months ago 5
MySQL Question

how to get a greater value with numbers containing 2 decimal points

is there any way we can find which is a greater version i.e to find if 1.0.1 is greater than 1.0.13 in php or mysql...

Any help appretiated,
Thank You

Answer

version_compare is a builtin PHP function used for exactly that (comparing version numbers); that'll do what you're asking.

version_compare('1.0.1', '1.0.13'); // -1
version_compare('1.0.1', '1.0.1'); // 0
version_compare('1.0.13', '1.0.1'); // 1

From the docs:

version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower.

http://php.net/version_compare