Converting string to integer, but preceding zero is being removed Follow up

This question has been answered so please close it... Thanks for the clarifications!!

I looked at the question above but there is an use case which we should consider before closing the issue:

I have a situation where I raise an order and the system generates a reference number as: 0000002443 I store that number as a string. When the system sends the order out, it sends two documents. One as a requisition with the above reference number and the other as a Purchase order with a reference: 0000002444

I need to be able to store the first reference number (i.e. 0000002443) as an Integer keeping the preceding zeroes and add +1 and store as a PO reference number (i.e.0000002444) to verify the orders later.

If I keep the first reference number as a String then I won't be able to add 1 to the reference number to get the PO reference Number.

It's a Follow up question: https://stackoverflow.com/questions/15025136/converting-string-to-integer-but-preceding-zero-is-being-removed

Jon Skeet
people
quotationmark

Simply put, an integer doesn't have a number of leading zeroes. It doesn't even have information about whether it's decimal, hex, or anything like that. It's just an integer.

If you really need to follow your existing design, I suggest you parse it as an integer, add one, and then repad with as many zeroes as you need to get back to the original length.

To be honest, if it's really just meant to be a number, it would be better if you stored it as a number instead of using a string at all.

people

See more on this question at Stackoverflow