WordPress.org

Ready to get started?Download WordPress

Forums

Popular Widget
[resolved] 4+ digit numbers have space not comma every third digit (4 posts)

  1. Jon Scaife
    Member
    Posted 2 years ago #

    When displaying counts above 1,000 the counts are displayed with a space every 3 digits rather than a comma. So 1 million would be shown as "1 000 000" rather than "1,000,000". It would be nicer to have the correct format used, and this would also prevent the number from line-breaking which makes it confusing to read. I've fixed this by making a single tweak to include.php as below...

    On line 241
    replace: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/"," ",$post->views).')</span>';
    with: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",",",$post->views).')</span>';

    Cheers

    http://wordpress.org/extend/plugins/popular-widget/

  2. Hax
    Member
    Plugin Author

    Posted 2 years ago #

    will do, thanks for the feedback

  3. jrf
    Member
    Posted 1 year ago #

    Actually, whether it should be a space, comma or dot is an internationalization issue and should depend on the chosen language of the installation.

    It'd be best to use the WP proprietary number_format_i18n( $number, $decimals = 0 ) function to get this right for every language in one go ;-)

    So, the code would then become:
    On line 241
    replace: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/"," ",$post->views).')</span>';
    with: $output .= '<span class="pop-count">('.number_format_i18n( $post->views, 0 ).')</span>';

    Hope this helps!

    Smile,
    Juliette

  4. Jon Scaife
    Member
    Posted 1 year ago #

    Agreed Juliette - but I found making a single character change was a lot simpler than figuring out internationalisation.. Thank you for doing the leg work (or just having the knowledge) to do it properly.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic