• Resolved Sho-Down

    (@sho-down)


    Is this possible in any way? Rather than showing the entire number for example 15,500, I want to show 15.5k so I use less space in my sidebar.

    So 10,000 would be 10k or 10,123 would be 10k as well or 10.1k. 25,500 would be 25.5k, etc.

    I’m using the shortcode to show the count number only so I’m styling it exactly how I’d like, just curious if there’s any way to round the numbers?

    https://www.ads-software.com/plugins/social-count-plus/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Claudio Sanches

    (@claudiosanches)

    You can use the social_count_plus_number_format filter and create a function the way you want to change the number in the format you need.

    Thread Starter Sho-Down

    (@sho-down)

    It’d be awesome if you could give me an example man, you’d save me many hours on Google trying to figure it out lol

    Plugin Author Claudio Sanches

    (@claudiosanches)

    In functions.php

    function my_social_count_plus_number_format($n) {
    
    if($n>1000000) return round(($n/1000000),1).'m';
            else if($n>1000) return round(($n/1000),1).'k';
            return number_format($n);
    }
    
    add_filter( 'social_count_plus_number_format', 'my_social_count_plus_number_format' );
    Thread Starter Sho-Down

    (@sho-down)

    Thanks for the code Paul but it’s not working for me for some reason. Any idea why? I’m using this code in my sidebar and not the widget:

    <?php echo number_format( get_scp_twitter(), 0, '', ',' ); ?>

    With your code in my functions.php file it still shows the numbers and no “k”

    I also tried:

    <?php echo get_scp_twitter(); ?>

    but it still didn’t work

    It doesn’t work for me either. The function my_social_count_plus_number_format works not to change 1300 followers in 1,3k followers. What is wrong with the code snippet?

    Can you please implement the function in the next version of the plugin?

    Plugin Author Claudio Sanches

    (@claudiosanches)

    @mirko It is impossible for me to do this, first we have various options as well, second for lack of time, third because nobody helps me, fourth because is something completely customized by the user and then it would be better to use the filter.

    Did anyone figure out a way to do this. I am trying to use the filter with no success.

    Thanks!

    So I got this working by doing this:

    <?php
                          $count = get_scp_facebook();
                          if ($count < 1000) {
                            echo round($count,0);
                          }
                          else if ($count > 1000000) {
                            echo round($count/1000000) . 'M';
                          }
                           else {
                            echo round($count/1000) . 'K';
                          }
                          ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Rounding the numbers (ie: 15,500 followers would be 15.5k)’ is closed to new replies.