user1027824
user1027824

Reputation: 51

PHP Show Trailing Zero on Non-Decimals

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

Answers (2)

Polynomial
Polynomial

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

rogerlsmith
rogerlsmith

Reputation: 6786

try number_format()

http://php.net/manual/en/function.number-format.php

Upvotes: 0

Related Questions