Page 1 of 1

math formula problems

Posted: Fri Nov 26, 2010 2:59 pm
by idahomike
I am pretty new to PHP but am having a math problem I am hoping to get some help with. I have broke this down to it's simplest form and still can not get the result I am looking for.

Code: Select all

<?php
	{
		$x = (0.25*(4000 / 65) - 0.0005*(4000 / 65)^2) / 100;
		printf($x);
		
	}
?>
When I run this code I get 0.13 with the expected result of 0.134911. This works for now as I can work out the decimal places later

When I change both occurrences of "4000" to "4200" I get 0.18 when the expected result is 0.140663

Can someone help me out with what is not working here. I have used this same formula in Excel spreadsheet and Visual basic and it works as expected.

Re: math formula problems

Posted: Fri Nov 26, 2010 3:17 pm
by McInfo
Use the pow() function for exponents. The caret (^) is a bitwise operator.

Re: math formula problems

Posted: Fri Nov 26, 2010 7:39 pm
by idahomike
McInfo wrote:Use the pow() function for exponents. The caret (^) is a bitwise operator.
This worked perfect, thanks for the info and quick response