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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.