Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:23:25+00:00 2026-05-27T21:23:25+00:00

This is a tricky question to ask. A friend of mine seeks help, and

  • 0

This is a tricky question to ask. A friend of mine seeks help, and I am not really into the project so it is difficult to describe the problem.

He has a shopping cart written in PHP, and in that shopping cart he wants all the product prices to be counted into a total price.

The problem is, all the prices are in a MySQL database. Displaying the prices (with decimals) is not a problem but, when these prices are counted and put in a variable, the decimals are not shown.

How can we solve this problem?

I will show you the code that he uses for displaying the prices in the shopping cart:

// Show cart
foreach($cart as $products) {
  // Split
  /*
    $product[x] -->
       x == 0 -> product id
       x == 1 -> hoeveelheid
  */
  $product = explode(",",$products);

  // Get product info

  $sql = "SELECT product_nummer, productnaam, verkoopprijs
         FROM product
         WHERE product_nummer = ".$product[0];  // Komt uit de sessie
  $query = mysql_query($sql) or die (mysql_error()."<br>in file ".__FILE__." on line ".__LINE__);
  $pro_cart = mysql_fetch_object($query);
  $i++;
  $price = $pro_cart->verkoopprijs; // variable price aanmaken zodat er opgeteld wordt

  echo "<tr>\n";
  echo "  <td>"."&nbsp;&nbsp;&bull;&nbsp;".$pro_cart->productnaam."</td>\n";     // naam
  echo "  <td><input type=\"hidden\" name=\"productnummer_".$i."\" value=\"".$product[0]."\" />\n"; // wat onzichtbare vars voor het updaten
  echo "      <input type=\"text\" name=\"hoeveelheid_".$i."\" value=\"".$product[1]."\" size=\"2\" maxlength=\"2\" /></td>\n";
  echo "  <td class=\"rechtsuitlijnen\">"."&#8364;&nbsp;".$pro_cart->verkoopprijs."</td>"."\n";
  $lineprice = $product[1] * $price;      // regelprijs uitrekenen > hoeveelheid * prijs
  echo "  <td class=\"rechtsuitlijnen\">"."&#8364;&nbsp;".$lineprice."</td>\n";
  echo "  <td><a href=\"javascript:removeItem(".$i.")\">X</td>\n"; //Product verwijderen
  echo "</tr>\n";


  // Total
  $total = $total + $lineprice; // Totaal updaten
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:23:26+00:00Added an answer on May 27, 2026 at 9:23 pm

    For displaying formatted numbers, you can use the PHP sprintf function ( http://php.net/manual/en/function.sprintf.php )

    <?php
    $money1 = 68.75;
    $money2 = 54.35;
    $money = $money1 + $money2;
    // echo $money will output "123.1";
    $formatted = sprintf("%01.2f", $money);
    // echo $formatted will output "123.10"
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really tricky question to ask as its very hard to explain
NOTE: This question is tricky (to decide whether it pertains to SO or not),
In this question, I am not going to ask How to horizontally center an
this is a tricky question I need to look into an app get the
This may be a tricky question to ask, but what I have is a
Now this is a tricky question, with the concern of not using tables or
This is a slightly tricky question to put into words. Basically I've been trying
i find this question tricky but what files store method signature info for xml
This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
I find this question a little tricky. Maybe someone knows an approach to answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.