#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171

    Proper use of number_format


    Hello;

    I have inconsistent type of prices (int or float) for example:
    230
    230.00
    I want to add .00 in front of all regardless of type. Would this be the right way of doing it?
    PHP Code:
     echo number_format($packages_row['TOTAL'],2); 
    Thanks
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Originally Posted by requinix
    No offense but have you tried it?
    Yes it works fine but it's always good to check I guess.
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    It's fairly straightfoward as far as functions go. You can't use round() because that keeps the result as a number (thus losing any insignificant zeroes); [s]printf() is another option but probably not as good as number_format().

IMN logo majestic logo threadwatch logo seochat tools logo