The quantity of the commodity is x, and then the total is added.

clipboard.png

$dishPrice = 0;
$dishAmount = 0;
$dishPriceV = 0;
          
$dishPrice = $dish->{"price"}; //  
$dishAmount = $dish->{"amount"}; // 
$dishPriceV += $dishPrice * $dishAmount;

print out each box

$dishPriceV

he will add the above
, for example, the first one is 14 is right
, but the second should be 5.6
he adds the above 14 to 19.6
the third should be 719.98 instead of 739.58

.
Mar.11,2021

your + = symbol must be wrong.


do you use loops to calculate the total price? You need to set total to 0 for each loop, and that's fine.


put $dishPriceV = 0; in the loop

can ps: put the code a little bit, just a few lines?


it seems that you are calculating directly with floating-point numbers. It is recommended to change floating-point numbers into integers and try again.

Menu