elentz Posted July 14, 2008 Share Posted July 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/ Share on other sites More sharing options...
GingerRobot Posted July 14, 2008 Share Posted July 14, 2008 Is $price 2? Seriously though, we need a bit more information. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-589913 Share on other sites More sharing options...
elentz Posted July 14, 2008 Author Share Posted July 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-589924 Share on other sites More sharing options...
GingerRobot Posted July 14, 2008 Share Posted July 14, 2008 You can: $foo = 100; $bar = $foo/2; echo $bar; //echos 50 Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-589926 Share on other sites More sharing options...
Barand Posted July 14, 2008 Share Posted July 14, 2008 I have tried $newprice = $price/2 and all I get is 1 What could be wrong here And that's not what we're looking for either. How are we supposed to know if anything is wrong when you don't even tell us what's in $price to start with? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-589945 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590071 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 Ok I think I found a clue as to what is going on.. For example $foo = <$100 $bar =$foo/2 does in fact = 50 if $foo = >$100 $bar=$foo/2 then the result is 1 I have no clue what this could be. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590079 Share on other sites More sharing options...
.josh Posted July 15, 2008 Share Posted July 15, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590081 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590085 Share on other sites More sharing options...
.josh Posted July 15, 2008 Share Posted July 15, 2008 so when are you gonna post some actual code? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590094 Share on other sites More sharing options...
AndyB Posted July 15, 2008 Share Posted July 15, 2008 Makes no sense does it? So far, that's all that does. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590101 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590103 Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 $price is a dollar amount ... Does that mean you have already formatted it before doing the division? what does var_dump($price_total); give you when you put it immediately before the divide? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590169 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 OK doing the var_dump I get the $price_total as it should be. One invoice was 81.75 and the other was 2901.12. So up until that point the variable is correct. Now what? Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590454 Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 I was wondering if you had commas in the number, or something like that, which would give problems Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590876 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 yeah it would have had a comma, at least the one example I tried it was 2,091.10 or something like that. The number is already formatted I think. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590883 Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590889 Share on other sites More sharing options...
dannyb785 Posted July 15, 2008 Share Posted July 15, 2008 this thread makes me lol Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590891 Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590905 Share on other sites More sharing options...
dannyb785 Posted July 15, 2008 Share Posted July 15, 2008 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( "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 Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590906 Share on other sites More sharing options...
elentz Posted July 15, 2008 Author Share Posted July 15, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590940 Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 Maybe next time you see my username just run the other direction! That's the plan Quote Link to comment https://forums.phpfreaks.com/topic/114721-solved-this-is-to-simple-for-me-to-get-right/#findComment-590977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.