There are exactly three cases and no judgement involved once you know the source format. What makes it error-prone is that the source format is not stated anywhere on the package — it has to be inferred from the segment lengths.
Never pad by adding a zero to the front of the whole number, and never trim a digit to make the length fit. Both produce a code that will match a different product or fail validation.