Format a number in PHP

By | July 15, 2015

Format a number in PHP

In this post let’s see how we can format a number in php to specific decimals, to group thousands, to separate decimals with another delimeter instead of using .(dot).

To acheive the above points we can use PHP’s number_format() function.

number_format — Format a number with grouped thousands, specific decimal digits etc.

Syntax:

The number_format() functions accepts upto four parameters. Having said that we can not pass three parameters too. We can only pass one,two or four parameters.

  • If only one parameter is given, then the number will be formatted without any decimals, but the number will be grouped to thousands with separator(,).
  • If two parameters are given, then the number will be formatted with decimals with a separator dot (“.”) in front, and will be grouped to thousands with separator(,).
  • If all four parameters are given, then the number will be formatted with decimals(in this case the third parameter will act as a separator) and and will be grouped to thousands with separator(fourth param).

Example:

🔥0

11 thoughts on “Format a number in PHP

  1. Donna

    I was just looking at your Format a number in PHP – PhpKnowledgeBase website and see that your site has the potential to become very popular.

    Reply
  2. google app store app

    It is appropriate time to make some plans for the
    future and it’s time to be happy. I have read this submit and if I could I want to recommend you few attention-grabbing things or tips.

    Perhaps you can write next articles regarding this article.
    I want to read even more issues approximately it!

    Reply
  3. how to set up google authorship

    Besides its google search itself, most people don’t use Google’s other features and tools that have
    a reputation of being more for the technologically inclined.
    Include a “Follow us on Google+” link on the business’s website that directs time
    for its Google+ page. Circles is the thing that every one
    of the high school and college users of Facebook are actually excited
    about.

    Reply
  4. linking google plus and facebook

    Hi there! Quick question that’s completely off topic.

    Do you know how to make your site mobile friendly?
    My website looks weird when viewing from my iphone.
    I’m trying to find a theme or plugin that might be able to correct this problem.
    If you have any recommendations, please share.
    Appreciate it!

    Reply
    1. Manigandan Arjunan Post author

      Hi,
      Can you please share your website url and which technologies you used to build the website. So that i can give you some best solutions.

      Thanks

      Reply
  5. quest bars

    Piece of writing writing is also a excitement, if you be familiar with after that you can write or else it is difficult to write.

    Reply
  6. mp3juice

    Wow that was odd. I just wrote an very long comment but after I clicked submit my comment didn’t show
    up. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say fantastic blog!

    Reply
  7. Anonymous

    Does your blog have a contact page? I’m having a tough time locating it
    but, I’d like to shoot you an email. I’ve got some creative
    ideas for your blog you might be interested in hearing.
    Either way, great website and I look forward to seeing it
    grow over time.

    Reply
  8. Doom Aimbot

    Wonderful web site, seeking details on a world of warships cheat.

    Reply
  9. MauriceWVita

    Awesome! Its really remarkable post, I have got much clear idea regarding from this article.

    Reply

Leave a Reply