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?
lvollmerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.