简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM