Jump to content

Trying to get a point two decimal outcome


JudgementDay

Recommended Posts

I'm having a little trouble when using the solution with my own code. I am getting the error 'unexpected ;':

 

$grandtotal = ((int)(($_SESSION['order']['contentvalue'] + $_SESSION['order']['deliverycost'] * 1.01 + $_SESSION['order']['paymentsurcharge'])) / 100;

 

I can understand why ';' is unexpected?

I don't know what that means.

It means you count every ( you have and every ) you have.  If the number doesn't match, then you have a problem.

 

When you start dealing with lines like that, it often is better to fill in a few temporary variables and use those.

$subTotal = $_SESSION['order']['contentvalue'] + $_SESSION['order']['deliverycost'] * 1.01;
$total = $subTotal + $_SESSION['order']['paymentsurcharge'];
$total = floor($total*100)/100;

 

Much easier to read and follow;

 

Is it possible to get '454.50' instead?

 

number_format should take care of that for you.

Hey bro,

 

I find temporary variables cause spaghetti and crufts up my code.

 

Hey, I found a solution to my problem. Its beyond my capacity to understand how it works, but all I know it does.

I don't have time to learn how it works. I am badly behind schedule.

 

$formula = ((int)((1 + 2 * 1.01 + 3) * 100)) / 100;
$grandtotal = sprintf("%01.2f", $formula);

 

Anyway, gotta run. Just came back to share the solution and mark as solved.

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.