Answer the question
In order to leave comments, you need to log in
Is there a number type in mysql that supports 0 at the beginning?
For example, I want to store the number 00254 (so that zeros are not cut out when saving)
I know about text, varchar and other types. And are there numbers?
Answer the question
In order to leave comments, you need to log in
When used in conjunction with the optional (nonstandard) attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.
If the task is to save in its original form, then store it in string.
If the number of characters is always known (in this example, 5), and it is required to pad with zeros:
>>> str_pad('254', 5, '0', STR_PAD_LEFT)
=> "00254"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question