Reputation: 51
I have a number stored in MySQL:
5430
PHP only displays:
543
How can I retain the last zero? Some numbers do not contain zeros.
Upvotes: 0
Views: 258
Reputation: 28316
Try this:
$number = str_pad($number, 4, '0', STR_PAD_RIGHT);
This will turn 1
into 1000
or 123
into 1230
. If you wanted 0001
or 0123
, you can use STR_PAD_LEFT
instead.
Here's the docs for str_pad()
: http://php.net/manual/en/function.str-pad.php
Upvotes: 1
Reputation: 6786
try number_format()
http://php.net/manual/en/function.number-format.php
Upvotes: 0