Jump to content

Round of into two decimal places


newphpcoder

Recommended Posts

Hi..

 

I encountered problem in rounding of numbers into two decimal places.

 

here is my sample code:

 

if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {
   $TAX = ($TotEarn - 7917);
   $TAX = (937.50 + ($TAX * .25));
   $TAX = number_format($TAX, 2, '.', '');
}

 

for example from this:

$TAX = ($TotEarn - 7917);
  $TAX = (937.50 + ($TAX * .25));

the output is: 1417.615

 

using this:

$TAX = number_format($TAX, 2, '.', '');

the output was : 1417.61

 

but it should be : 1417.62

 

Thank you

Link to comment
Share on other sites

if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {

$TAX = ($TotEarn - 7917);

$TAX = (937.50 + ($TAX * .25));

//printf('%0.5f; %s', $TAX, number_format($TAX, 2, '.', ','));

$TAX = number_format($TAX, 2, '.', '');

//$TAX = round($TAX, 2);

}

 

$TAX = (9837.46 - 7917);

$TAX = (937.50 + (1920.46 * .25)); // (937.50 + 480.115 )

$TAX = number_format(1417.615, 2)

 

Link to comment
Share on other sites

I tried some testing:

$TAX  = ($TotEarn - 7917); // 1920.46

$TAX = ($TAX * . 25); // 480.115

 

$TAX = round($TAX, 2) // 480.11

 

but when I tried this:

 

$TAX = (480.115);

$TAX = round($TAX , 2); // 480.12

 

I notice that if the variable is  = actual numeric it works but if it is came from variable it did not work :(

 

I really don't know what to do :(

 

Thank you

 

 

 

 

Link to comment
Share on other sites

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.