Jump to content

[SOLVED] PHP Arithmetic and Decimal points


Omzy

Recommended Posts

I'm now trying to add up values to get a subtotal:

 

 
$subtotal=0;

foreach($_SESSION as $value)
{
$total=number_format($value[2]*$value[3], 2);

$subtotal=number_format($subtotal+$total, 2);
}

echo $subtotal;

 

But this does not always display the correct value for $subtotal

Use number_format just before echo. Until then just do your math without worrying about decimals.

 

$subtotal=0;

foreach($_SESSION as $value)
{
$total=$value[2]*$value[3];

$subtotal=$subtotal+$total;
}

echo number_format($subtotal,2);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.