且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用逗号格式化的 MySQL 数据库中的数字

更新时间:2023-02-11 07:54:37

这是您要找的吗?

http://php.net/manual/pt_BR/function.number-格式.php

number_format( $views, 0 , "." , "," );

没有小数位.点表示小数点,逗号表示千位分隔符.

So i'm currently running a php website that pulls data from a mysql database. At the moment i have a column, we can call this "views" the numbers that are in this column are just digits and not recognised as numbers and therefore have no commas to separate the numbers. So the code onsite will look something like this:

<div><b>Views: </b><?=$views?></div>

I have been able to take a column that is showing seconds to be formated in a minuite/seconds format:

<div><b>Length: </b><?=gmdate("i:s", $length)?></div>

But I am unable to find out how I can format the numbers to include commas, at the moment a number will pull as "1000000" but I would like to format it so that the user will see "1,000,000".

Thanks in advance.

p.s If you do know how to do this and know of any documentation could you link me to that also.

Solved by "Paulo Lima"

Code would look like:

Views:

Is this what you are looking for?

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

number_format( $views, 0 , "." , "," );

No decimal places. Dot for decimal point, comma for thousands separator.