Billy
Billy

Reputation: 15706

How can I print number in 4 digit?

I want to print a list of numbers in php.
But I want to print 4 digits of numbers (preceding with zero if necessary), e.g.
0001, 0009, 0076, 0129, 1234

What should I do?

Upvotes: 2

Views: 2715

Answers (4)

pavium
pavium

Reputation: 15118

Look at the PHP Language Reference Manual and search for zero-padded integers

The link gives the sprintf details, but the format string information applies to related functions like printf

Upvotes: 0

ghostdog74
ghostdog74

Reputation: 342313

printf ('%04d' ,$num)

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

printf("%04d", $num);

Upvotes: 15

Quentin
Quentin

Reputation: 943207

printf

Upvotes: 1

Related Questions