如何在PHP中为数字添加逗号 [英] How can I add commas to numbers in PHP
本文介绍了如何在PHP中为数字添加逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在数字上添加逗号.让我的问题变得简单.
I would like to know how can I add comma's to numbers. To make my question simple.
我想更改此内容
1210 views
收件人:
1,210 views
和:
14301
到
14,301
,以此类推,以获取更大的数字.可以使用php函数吗?
and so on for larger numbers. Is it possible with a php function?
推荐答案
来自php手册我假设您想要英语格式.
I'm assuming you want the english format.
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation with a decimal point and without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
我的2美分
这篇关于如何在PHP中为数字添加逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文