number_format_i18n Function Reference and Usage

In a previous post, I wrote about the usage of the date_i18n function in WordPress called date_i18n Function Reference and Usage.

This post will address how to properly format displaying values (numbers) according to the WordPress blog settings.

The function to use for this is number_format_i18n – Read the reference material on wordpress.org

WordPress comes with a lot of nice features to reduce developer headaches and ensure things just work no matter where you use your code.

The usage is much easier than the date-function, as it is a simple function that accepts only a single parameter, the value to be displayed.

Usage:


$thenumber = 1420.3321;
echo number_format_i18n($thenumber,2);

The output will display the number in the correct localized format for your blog, use the second parameter to set the number of decimals.

Edit: Finally, after Brent made a comment back in 2009, I have updated the post to mention decimals.

Read also  301 redirects for 404 spam pages - WordPress Style
Popular searches to this page
  • and usage

2 thoughts on “number_format_i18n Function Reference and Usage”

  1. Brent Shepherd

    Lars, thanks for publishing this post. I hadn’t realised until today there was a function to easily take care of number formatting. The more discussion on it the better!

    One correction, number_format_i18n can optionally take a second parameter – $decimals – representing the number of decimals to include.

  2. I never got around to saying thanks or actually updating the post. I just did, almost 9 years later, yikes – time flies. Anyway – Thank you 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

Free eBook - 

Guide to success with SEO

Join the newsletter for more interesting articles, discount code for SEO Booster Pro and much more.

Guide to success

with SEO 2018

FREE

We respect your privacy and do not share your details with others

Join our newsletter and get a free eBook, interesting articles, discount codes and much more.