Jump to content

Recommended Posts

Howdy, I am having a problem here with rounding. I cannot seem to figure out what is going on.

 

Here is the code.

 

if($hardnesspicked == Stainless){
	$odpicked = 5;
	$tpi = .953;

	echo 'You have picked stainless steel on the kasto saw, the time per inch will be '.$tpi.'<p>';

	//let's do the math and get the PPH

	$mpp = $odpicked * $tpi;


	echo ''.$mpp.' MPP <p>';


	$mpp = round($mpp, 2);




	echo ''.$mpp.' formatted mpp<p>';



	$pph = 60 / $mpp;

	$pph = round($pph, 3);

	echo 'This Job will have a PPH = '.$pph.'.<p>';

}

 

 

Here is the output:

You have picked stainless steel on the kasto saw, the time per inch will be 0.953

 

4.765 MPP

 

4.76 formatted mpp

 

This Job will have a PPH = 12.605.

 

4.765 should be rounding up to 4.77

 

I cannot figure out what i am doing wrong and why this number is not rounding to 4.77 Can anyone help me figure this out?

Link to comment
https://forums.phpfreaks.com/topic/136609-problems-with-rounding/
Share on other sites

ummm.... i need pph to be a 3 point decimal... and had the mpp came out to 4.77 instead of 4.76 my pph would be correct... which should be 12.579 instead of 12.605. The problem is that the round is not taking 4.765 and turning it into 4.77.

I just ran into a problem... if the number to be round is 4.352, this will round the number incorrectly to 4.36.... I need the number to round up if the 3rd decimal place is 5-9 and round down if the third decimal place is 0-4. Any more suggestions?

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.