用逗号格式化的 MySQL 数据库中的数字 [英] Number from MySQL database to be formated with comma

查看:74
本文介绍了用逗号格式化的 MySQL 数据库中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前正在运行一个从 mysql 数据库中提取数据的 php 网站.目前我有一列,我们可以称之为视图",该列中的数字只是数字,不被识别为数字,因此没有逗号来分隔数字.所以现场的代码看起来像这样:

<div><b>视图:</b><?=$views?></div>

我已经能够将一列显示秒的格式设置为分钟/秒格式:

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

但我不知道如何格式化数字以包含逗号,目前一个数字会被拉为1000000",但我想对其进行格式化,以便用户看到1,000,000".

提前致谢.

p.s 如果您知道如何执行此操作并知道任何文档,您也可以将我链接到该文件.

由Paulo Lima"解决

代码看起来像:

观看次数:

解决方案

这是您要找的吗?

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.

这篇关于用逗号格式化的 MySQL 数据库中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆