gpt4 book ai didi

php - 如何在数字的每 3 位数中放置逗号

转载 作者:可可西里 更新时间:2023-10-31 23:52:27 25 4
gpt4 key购买 nike

例如,我想在数字的每 3 位数字中放置一个逗号。

$number = 1234567;
// should print 1,234,567

我该怎么做?

更新:请看这段代码

<?php
/**
* Get Popularity Text of a Domain via Alexa XML Data
*
* @return string|FALSE text or FALSE on error
*/
function alexa_get_rank($domain)
{
$alexa = "http://data.alexa.com/data?cli=10&dat=s&url=%s";
$request_url = sprintf($alexa, urlencode($domain));


$xml = simplexml_load_file($request_url);
if (!$xml) {
return FALSE;
}

$nodeAttributes = $xml->SD[1]->POPULARITY->attributes();
$text = (int) $nodeAttributes['TEXT'];

$num = number_format($text);

return $num;
}

在此只返回 3 位数。

最佳答案

使用

echo number_format('1234567');

PHP Manual : number_format()

关于php - 如何在数字的每 3 位数中放置逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13356213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com