I
I
Ilya Beloborodov2015-11-16 17:24:57
MySQL
Ilya Beloborodov, 2015-11-16 17:24:57

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

3 answer(s)
W
wol_fi, 2015-11-16
@wol_fi

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.

https://dev.mysql.com/doc/refman/5.5/en/numeric-ty...
That's how you can.

M
Mikhail Osher, 2015-11-16
@miraage

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"

D
Dimonchik, 2015-11-16
@dimonchik2013

what does life-giving PHP do to people!
and they also say...
TS, php.spb.ru/php/printf.html will solve your problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question