15. E – Commerce Website Tutorial – PHP Shopping Cart Money Format Currency

www.developphp.com In this 15th video we will learn to format money and numbers using the money_format() and number_format() functions in PHP. The E – Commerce Web Site we will be assembling is one in which all of the inventory is in a MySQL database and we offer a custom PHP cart for a unique shopping experience.

13 Comments

  • with the number_format that i used i have just found that if i go over £1000.00 it messes the cart total up which is strange so i have gone to the money_format which sorts it all out
    the only thing that was a small thing is displaying the £ symbol for the british money it didnt like it so i leave it in the code as it was and then used this to display the money setlocale(LC_MONETARY, “en_GB”);
    $pricetotal = money_format(“%!10.2n”, $pricetotal); note the ! it hides the symbols

  • @adrian281990
    Thanks adrian, this one worked great for me..When I used the money_format() it would not render the cart.php page. I did not need the “echo…and I put one for each variable ($price, $priceTotal, and $cartTotal).
    Thanks

  • @adrian281990
    Thanks adrian, this one worked great for me..When I used the money_format() it would not render the cart.php page. I did not need the “echo”…and I put the number_format() for each variable ($price, $priceTotal, and $cartTotal).
    Thanks

  • The example used by adrian281990 can also be applied to your index.php homepage to add the proper decimal points and commas. Leave the “extra $ signs.” as this code does not apply it.
    Put $price = number_format($price, 2);
    BELOW…
    $price=$row[“price”];
    and that will render the correct format

  • Using the number_format which you need to do on Windows servers, I noticed that the $price variable can’t be used in calculations again. SO BE sure to use the number_format function further down after ALL calculations have been done using the $price variable. GREAT Tutorials Adrian. I can’t wait to put my store up!

  • sir adam, i have errors on your tutorial when i click my add to cart button in my product page..Errors came out in cart.php!!! Like this…Fatal error: Call to undefined function money_format() in C:\xampp\htdocs\MyOnlineStore\cart.php on line 120
    Hope you can help me…thank you so much in advance sir….

Leave a Reply

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