简体   繁体   English

PHP显示非十进制尾随零

[英]PHP Show Trailing Zero on Non-Decimals

I have a number stored in MySQL: 我在MySQL中存储了一个数字:

5430 5430

PHP only displays: PHP仅显示:

543 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 . 这将把1变成1000123变成1230 If you wanted 0001 or 0123 , you can use STR_PAD_LEFT instead. 如果需要00010123 ,则可以改用STR_PAD_LEFT

Here's the docs for str_pad() : http://php.net/manual/en/function.str-pad.php 这是str_pad()的文档: http : str_pad()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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