SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the difference: echo number_format($totalCost, 2, ".", ",") & echo $totalCost

    Hi,

    Quick question. What is the difference:

    PHP Code:
    Total: $<?php echo number_format($totalCost2"."","); ?>
    PHP Code:
    Total: $<?php echo  $totalCost;?>
    Matt.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Well the number format. Duh.

    Basically the additional is just to guarantee the output is formated in the right way (in this case, money).

    Most likely, this is because $totalcost is a calculated number (like 56000.0), and it needs to be displayed human-comfort-readable (56,000.00). Note the extra 0 and thousands seperation.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •