Format a number with grouped thousands

I have the following function:

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'); 
}

How do I make it format a number to include a comma in the thousandths place? For example, 50000 should become 50,000.

Answers


Use number_format():

number_format($number);

Need Your Help

Crash in debug mode (F5) when calling a native C++ method

c# c++ pinvoke debug-mode

I am trying to call a C++ method by using LoadLibrary, GetProcAddress and GetDelegateForFunctionPointer.

My app doesn't react at the didSelectRowAtIndex: method

ios uitableview core-data

i don't know what I am doing wrong, but my app is not working as expected. I have a tableview controller, and today I have included the didSelectRowAtIndexPath: method to open a detail view from the