#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220

    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. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
  4. #3
  5. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    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. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    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