Jump to content

[SOLVED] This is to simple for me to get right!!!


elentz

Recommended Posts

I have a variable let's say $price  and I want to divide that in half.  I also want to make sure that it is in the dollar and cents format.  But I haven't gotten that far.

 

I have tried

 

$newprice = $price/2

 

and all I get is 1

 

What could be wrong here

 

Thanks

Link to comment
Share on other sites

Not what I am looking for.  I want to take $price and divide it in half.  I need to take the price and make it into another variable.  Something like $price would be 100 and I want to divide it in half.  I need to show the result of that division.

 

I thought I could just do something like $result = ($price/2)

 

Thanks for any help.

Link to comment
Share on other sites

Sorry about that I was rushed to answer.  Anyway.  $price is a dollar amount and what I am trying to do is get whatever half of that is into another variable.  I will need it in a 2 digit format, then I want to put it into a field in a pdf.  I have the pdf part working the way I want.  I just need to get this simple math worked out.  As I get older the more simple the issue the harder it becomes!!

 

Thanks.

Link to comment
Share on other sites

wait wait wait, are < and > supposed to be less/greater than signs there? As in, if $foo is less than or equal to $100, like say, 99 or 75 or 13, and you divide it by 2, the answer is 50?  And if $foo is greater than or equal to $100 like say 150 or 197 or 1,002,043,123 and you divide it by 2, the answer is 1? How is that possible?

Link to comment
Share on other sites

Yes the < and > are greater and lessor signs.  I ran four different numbers  two were under 100.00 and two were over 100 like 2901.12 and 8500.00  Everything over 100 resulted in 1 and the others were right.  Makes no sense does it?

Link to comment
Share on other sites

if($downpaymentinvoice == 1)

{// *******************totals Block*********************
$dwnpmt= $price_total/2;
$totalBlock=array("120","232","40", "125");
$totalText=
          "Down Payment Amount          $ ".[font=Verdana]$dwnpmt[/font]."\n";


$pdf->addDescBlock($totalText, "Down Payment Due", $totalBlock);

$blurbBlock=array("10","265","150", "60");
$blockText="Payment must be received before work commences.";
$pdf->addDescBlock($blockText, "Attention:", $blurbBlock);
}
else

 

$price_total is a a total of parts sold from this snippet of code for an invoice PDF.  What I am trying to do is take that amount ($price_total) and if $downpaymentinvoice = 1 then I want the $dwnpmt in the block and to be 1/2  or 50% of the $price_total.

Link to comment
Share on other sites

OK. Here's a tip when someone is trying to help.

 

When they ask for the output from a particular bit of code, copy and paste the actual output. Don't just give an answer like "It's what it should be". The exact content is significant, that's why they asked for it.

 

A comma is a non-numeric character so

echo 2,500/2;    // --> 1 as it only considers the numeric characters up to the first non-numeric

echo 2500/2      // --> 1250

 

Format your numbers only on final output after all calculations have been completed.

Link to comment
Share on other sites

Glad you're amused, it makes me rather annoyed.

 

 

1 ) He was prompted for the content of $price early on

How are we supposed to know if anything is wrong when you don't even tell us what's in $price to start with?

 

2 ) Even when specifically asked again for output from var_dump()he couldn't even give an accurate response (2901.12 was given, when it was really string( 8 ) "2,901.12".

 

Time waster IMO and duly noted

Link to comment
Share on other sites

Glad you're amused, it makes me rather annoyed.

 

 

1 ) He was prompted for the content of $price early on

How are we supposed to know if anything is wrong when you don't even tell us what's in $price to start with?

 

2 ) Even when specifically asked again for output from var_dump()he couldn't even give an accurate response (2901.12 was given, when it was really string(8) "2,901.12".

 

Time waster IMO and duly noted

 

10000% agreed. If he showed his code at the beginning, it would've taken one person to say "remove the commas" but alas, he didn't think it was necessary

Link to comment
Share on other sites

Sorry guys for all the mis-direction on my part.  I just know enough to be dangerous.  And I proved that here didn't I?  I really appreciate all your help.  I see now what you mean about the commas.  I will remove the formatting and go from there.  Mostly the reason I didn't know about the formatting of the price_total is that it is done in another piece of code that calls the one I was working with.  The code itself is for sure not my doing, I am only adding snippets of code to make it do what I want.

 

Again, I apologize for all the time you wasted on my problem when it turned out to be so simple!  But, i did say it was so simple I couldn't figure it out didn't I?  :)

 

Maybe next time you see my username just run the other direction!

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.