• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

PHP multiplication and division

$taxburden =  number_format(($Medrealestatetax / $income) * 100,2);

I am using this to store a number called $taxburder. it divides, but does not multiply by 100. Is my syntax wrong?
0
lvollmer
Asked:
lvollmer
  • 10
  • 6
  • 2
1 Solution
 
hieloCommented:
have you verified that the variables actually have numeric values and/or that the variable names are spelled correctly?

0
 
lvollmerAuthor Commented:
$income=intval( $_POST['income'],10);
$medHHincome = number_format($r["medHHincome"]);
$hometax = number_format(($income*$tax_homeval)/100, 2);

here are my variables - I know income is a numeric value because I enter it in a field myself
0
 
Rok-KraljCommented:
I think you have a logical error here. I think if you * 100 * 100 multiply twice, then your algorithm will work.

Try this code below, if there really is difference between values, it is a PHP's fault, otherwise it's yours.
echo ($Medrealestatetax / $income) * 100;
echo '<br>';
echo ($Medrealestatetax / $income);

Open in new window

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
hieloCommented:
on your original post you were using:
$Medrealestatetax

On your latest post you are now using a different variable. Use var_dump() to inspect the variables  in question:

var_dump($Medrealestatetax);//what does it give you?
0
 
lvollmerAuthor Commented:
to answer your first question, here is what i got:

(8,404 / 75000) * 100;
(8,404 / 75000);

let me try this other one
0
 
hieloCommented:
the commas are your problem. Get rid of them:

$Medrealestatetax=str_replace(",", "", $Medrealestatetax);
$taxburden =  number_format(($Medrealestatetax / $income) * 100,2);
0
 
lvollmerAuthor Commented:
that gives me a 0.00
0
 
lvollmerAuthor Commented:
the var dump on that is 0 as well, which is prob why i am getting 0.00
0
 
lvollmerAuthor Commented:
what I am trying to do is take Medrealestatetax divide it by the income, then multiply by 100 and display it in this format #.##%

the medrealestate tax and income need to be displayed as dollars, so if the user enters 75000 , it should display as 75,000
0
 
hieloCommented:
well that is your problem. IF the variable has 0.00 the end result will be zero. You need to trace your code back to the place where you are assigning a value to the variable in question and then inspect the "SOURCE" to see why it has zero. (at this point I am not clear which variable is giving you problems. You followed up with so many variables after your original post that I don't know which variable is the one giving you problems).

By source I meant that if you are querying a db and then take a db result to assign something to the variable in question, then you also need to be certain that the db result is not returning zero.
0
 
Rok-KraljCommented:
Run my code, paste the output!
0
 
lvollmerAuthor Commented:
i have attached the code here, do you see what is wrong?
if(isset($_POST['simple'])) 
	  
	  $state = $_POST['simple'];
	  $county = $_POST['simple_child'];
	  $income=intval( $_POST['income'],10);


//grab all the content
while($r=mysql_fetch_array($result))
{	
     
$tax_homeval= $r["tax_homeval"];
$tax_income= $r["tax_income"];
$taxpain= $r["Taxpain"];
$Medvalue = number_format($r["Medvalue"]);
$medHHincome = number_format($r["medHHincome"]);
$Medrealestatetax=str_replace(",", "", $Medrealestatetax);
$taxburden =  number_format(($Medrealestatetax / $income) * 100,2);   
$hometax = number_format(($income*$tax_homeval)/100, 2);
$incometax = number_format(($income*$tax_income)/100, 2);
$format_incometax = number_format($income);
   


   //display the row
   echo "State: $state <br /> County: $county <br />Your income: $$format_incometax  <br /> Your Tax Burden: <strong>$taxburden%</strong><br /> - <Br /> <strong>About this county:</strong> <br /> Median Home Value:  $$Medvalue <br /> Median Household Income: $$medHHincome<br /> Median Real Estate Tax: $$Medrealestatetax <br/> Taxes as percentage of median home value: $tax_homeval%<br /> Taxes as percentage of median home value: $tax_income% 
   ";
   
  <br /><br /> var_dump($Medrealestatetax);
}	  

Open in new window

0
 
lvollmerAuthor Commented:
rok - i did and it did not work
0
 
hieloCommented:
>>$Medrealestatetax=str_replace(",", "", $Medrealestatetax);
does your db table have a field named Medrealestatetax? IF yes, then the line above should be:
$Medrealestatetax=str_replace(",", "", $r['Medrealestatetax'] );
0
 
lvollmerAuthor Commented:
it does. let me try this
0
 
lvollmerAuthor Commented:
i think that worked, let me run some tests
0
 
hieloCommented:
Ding-Dong!
0
 
lvollmerAuthor Commented:
LOL!!! SORRY! THAnks Hielo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 10
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now