如何用逗号重新格式化数字 [英] how to reformat a number with commas

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

问题描述

我有一行代码可以获取表中的行数,然后显示该数.在这种情况下,它将显示下载数量.

I have a line of code that get a count of rows in my table and then display the count. In this case it display the number of downloads.

现在计数非常小,但是当计数变大(大于1000)时,我想将其格式化以逗号显示在正确的位置示例中:

Right now the count is very small but when it gets larger ( great than 1000) I would like to format it to display with commas in the correct spots example:

1,000

100,000

1,000,000

1,000,000

或者用. 1.000 1.000.000

Or perhaps with a . 1.000 1.000.000

最简单的方法是什么?

推荐答案

您可以使用 number_format() 功能:

You can use the number_format() function:

$str = number_format($number);

使用."而不是,":

$str = number_format($number, 0, ',', '.');

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

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