English 中文(简体)
表格a,有数千
原标题:Format a number with grouped thousands
  • 时间:2012-05-03 02:01:17
  •  标签:
  • php

我有以下职能:

function getPostViews($postID){
    $count_key =  post_views_count ;
    $count = get_post_meta($postID, $count_key, true);
    if($count==  ){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key,  0 );
        return __( 0 View , mm );
    }
    return $count. __(  Views , mm ); 
}

我如何把一ma子列入一 number? 例如,5 500万人应当成为50 000人。

最佳回答

使用 number_format(:

number_format($number);
问题回答

您可使用_format

$number=number_format($number);

你的编号格式使用是正确的,使你正在寻找冰层。 我认为,你正在着手改变行文的格式,这就是说,你正在对数字进行格式化,并自行加以节省。

例如:

$count = 5000;
$count = number_format($count);
//$count is no longer equal to 5000, it is now a string 5,000

如果使用临时变量,那么你原来的计值变量就赢得了一定变化,如果你重新书写数据库,则仍然采用你想要的格式。

例如:

$count = 5000;
$tmpCount = 0;
$tmpCount = number_format($count);
// $count is still 5000, and $tmpCount now holds the value 5,000.

你们的法典经过更新后,我假定你只想拿走 com子分离值的 met子吗?

    function setPostViews($postID) {
    //Set initial variables
    $count_key =  post_views_count ;
    $tmpCount = 0;
    $count = get_post_meta($postID, $count_key, true);

    if($count ==   ) {
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key,  0 );
    } else {
        $count++;
        //Set tmpCount variable to hold comma separated value
        $tmpCount = number_format($count);

        //Comma separated value is passed into your function
        update_post_meta($postID, $count_key, $tmpCount);
    }
}

你们想要的是什么呢? 或者如果你在向用户显示时只想以这种方式来排列这一编号,那么,在盘问后, d(而不是按 separated分开),就能够保持正确性,从而节省 d的价值,并产生与我上述做法完全相同的ma变。 然后,就任何db项功能而言,是指计值变量,以及任何用户产出功能,均使用tmpCount变量。

我再次希望回答你的问题,如果没有,请澄清。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签