How do you store numbers with leading zeros?\
shkspr.mobi
shkspr.mobi
To be concrete, let's suppose we're talking about 5-digit, zero-padded numbers. Those are integers in the range [0, 99999]. Any database system will allow you to model this value and enforce the constraint in the DDL.
Storage is compact, the constraint is system-enforced, and querying works correctly, i.e., you get the right result whether your query bounds are zero-padded or not (with some assumptions about permitted literal syntax).
The zero-padding is only relevant for presentation, which should not be mixed up with the modeling in any case.
Also, this assumes fixed-length. If, for example, 5, 05, 005, 0005 and 00005 are all valid and different, then just use a string.
I go with string because serial numbers, despite having the word "number" in the phrase, are not necessarily numeric. Hexadecimal numbers have letters (for example), but we still call them "numbers" ;)
struct NumberWithLeadingZeros {
leading_zeros: u64,
number: Vec<u64>
}
Then implement some traits for it add, sub, pow, to_string etc. and work with it.Or do something else that fits exactly your needs.