[英]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
变成1000
或123
变成1230
。 If you wanted 0001
or 0123
, you can use STR_PAD_LEFT
instead. 如果需要0001
或0123
,则可以改用STR_PAD_LEFT
。
Here's the docs for str_pad()
: http://php.net/manual/en/function.str-pad.php 这是str_pad()
的文档: http : str_pad()
try number_format() 尝试number_format()
http://php.net/manual/en/function.number-format.php http://php.net/manual/zh/function.number-format.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.