Storing numeric values
Attributes that store number values, which need to be sorted or compared, need to use the technique of zero padding so that they work correctly when using lexicographical comparison. If you store two number values 2
and 10
, a normal lexicographical comparison will result in the value 2
being greater than 10
. This is, of course, not exactly what you would expect to get when comparing these values as numbers.
Note
The solution is to store the number values with padding for the right number of digits.
We will store 2
as 02
. Now a lexicographical comparison between 02
and 10
will return what you expect! In order to pad your data correctly, you need to know the limits of the number values that will be stored. If you know how large a number is to be stored, you can then pad each number that is being stored in your attributes with the right number of digits.
If you need to store negative numbers as attribute values and want to compare them, then storing them with just a zero...