# Round of into two decimal places

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

Actually you are using the wrong function to do the rounding.

There is a function for rounding: round();

``````echo round(1417.615,2);
``````

I tried it also but still same output

Thank you

That’s strange. For me it is working correct. Maybe some setting in your PHP is not correct.

where in my settings?

Thank you

I have read soms more about it and it doesn’t appear to be a settings problem. Actually it has to do with binary values.
but I can’t explain that.

However I might have come across a solution.

you can update your PHP version or you can give a third parameter to the round function.
Like: round(1.345, 2, ROUND_HALF_UP).
I might have written the parameter wrong, but if you try it and get errror, look on google with the parameter I gave you. Good luck

I tried this:

``````
if(\$W4_STATUS == 2 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 = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');

}

``````

and it works in my localhost but in server not

Just to satisfy my curiosity, could you run this code and let us know what you got?

<?php
\$TAX = 417.61552;
printf(‘%0.f - %0.2f - %s’, \$TAX, \$TAX, number_format(\$TAX, 2, ‘.’, ‘,’));
?>

This parameter needs version 5.3 and it should be PHP_ROUND_HALF_UP

I can’t change my php version…
Is there any solution

Uhm perhaps write your own rounding function? Can you do that?

No

You need to recheck your code if the php function round(number, number of float digits to be rounded); is not working fine with your code.
If you still facing problem to round it off just you can go for Javascript function roundNumber(rnum, rlength)

Perhaps you missed seeing my request. Could you run the code below and let us know what you got?

<?php
\$TAX = 417.61552;
echo round(\$TAX, 2).‘<br/>’;
printf(‘%0.f - %0.2f - %s’, \$TAX, \$TAX, number_format(\$TAX, 2, ‘.’, ‘,’));
?>

When I tried your code the output is :

417.61552-417.62-417.62

but when I tried:

``````
if(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 7917 AND \$TotEarn <= 12500) {
\$TAX = (\$TotEarn - 7917);
\$TAX = (937.50 + (\$TAX * .25));
// \$TAX = round(\$TAX, 2);
\$TAX = round(\$TAX, 2);
//\$TAX_Ded = number_format(\$TAX, 2, '.', '');
\$TAX_Ded=printf('%0.f - %0.2f - %s', \$TAX, \$TAX, number_format(\$TAX, 2, '.', ','));

}

``````

the output is:

1417.610000 - 1417.61 - 1,417.61

Thank you

So it is working as it should.

Just to see that your code works too by changing the last line to this:

printf(‘%0.f - %0.2f - %s’, \$TotEarn, \$TAX, number_format(\$TAX, 2, ‘.’, ‘,’));

Lets us know what you got.

I tried this:

``````
if(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 7917 AND \$TotEarn <= 12500) {
\$TAX = (\$TotEarn - 7917);
\$TAX = (937.50 + (\$TAX * .25));

\$TAX = round(\$TAX, 2);
//\$TAX_Ded = number_format(\$TAX, 2, '.', '');

\$TAX_Ded = printf('%0.f - %0.2f - %s', \$TotEarn, \$TAX, number_format(\$TAX, 2, '.', ','));
//\$TAX_Ded=printf('%0.f - %0.2f - %s', \$TAX, \$TAX, number_format(\$TAX, 2, '.', ','));
}

``````

the output is:

9837.460000 - 1417.61 - 1,417.61

Thank you

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

OK, I see your problem. Since your version of PHP does not support ROUND_HALF_UP I would suggest you to do this:

change this line
\$TAX = (937.50 + (\$TAX * .25));

to this:
\$TAX = (937.500001 + (\$TAX * .25));

I tried this and it works,but my problem now is what should I need to my other condition here is my whole code for TAX deduction:

``````
if(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 0 AND \$TotEarn <= 2083){
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 0 AND \$TotEarn <= 2083){
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2083 AND \$TotEarn <= 2500) {
\$TAX = (\$TotEarn - 2083);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');

}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2083 AND \$TotEarn <= 2500) {
\$TAX = (\$TotEarn - 2083);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2500 AND \$TotEarn <= 3333) {
\$TAX = (\$TotEarn - 2500);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2500 AND \$TotEarn <= 3333) {
\$TAX = (\$TotEarn - 2500);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 3333 AND \$TotEarn <= 5000) {
\$TAX = (\$TotEarn - 3333);
\$TAX =(104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 3333 AND \$TotEarn <= 5000) {
\$TAX = (\$TotEarn - 3333);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 5000 AND \$TotEarn <= 7917) {
\$TAX = (\$TotEarn - 5000);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 5000 AND \$TotEarn <= 7917) {
\$TAX = (\$TotEarn - 5000);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 7917 AND \$TotEarn <= 12500) {
\$TAX = (\$TotEarn - 7917);
//\$TAX = (937.50 + (\$TAX * .25));
\$TAX = (937.500001 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');

//\$TAX_Ded = printf('%0.f - %0.2f - %s', \$TotEarn, \$TAX, number_format(\$TAX, 2, '.', ','));
//\$TAX_Ded=printf('%0.f - %0.2f - %s', \$TAX, \$TAX, number_format(\$TAX, 2, '.', ','));
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 7917 AND \$TotEarn <= 12500) {
\$TAX = (\$TotEarn - 7917);

\$TAX = (937.50 + (\$TAX * .25));
// \$TAX = round(\$TAX, 2);
//printf('%0.5f; %s', \$TAX, number_format(\$TAX, 2, '.', ','));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
//\$TAX_Ded=printf('%0.f - %0.2f - %s', \$TAX, \$TAX, number_format(\$TAX, 2, '.', ','));

}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 12500 AND \$TotEarn <= 22917) {
\$TAX = (\$TotEarn - 12500);
\$TAX = (2083.33 + (\$TAX * .30));
//printf('%0.5f; %s', \$TAX, number_format(\$TAX, 2, '.', ','));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');

//\$TAX_Ded=printf('%0.f - %0.2f - %s', \$TAX, \$TAX, number_format(\$TAX, 2, '.', ','));

}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 12500 AND \$TotEarn <= 22917) {
\$TAX = (\$TotEarn - 12500);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 22917 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 22917 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}

elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 0 AND \$TotEarn <= 3125) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 0 AND \$TotEarn <= 3125) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 3125 AND \$TotEarn <= 3542) {
\$TAX = (\$TotEarn - 3125);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 3125 AND \$TotEarn <= 3542) {
\$TAX = (\$TotEarn - 3125);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 3542 AND \$TotEarn <= 4375) {
\$TAX = (\$TotEarn - 3542);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 3542 AND \$TotEarn <= 4375) {
\$TAX = (\$TotEarn - 3542);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 4375 AND \$TotEarn <= 6042) {
\$TAX = (\$TotEarn - 4375);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 4375 AND \$TotEarn <= 6042) {
\$TAX = (\$TotEarn - 4375);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 6042 AND \$TotEarn <= 8958) {
\$TAX = (\$TotEarn - 6042);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 6042 AND \$TotEarn <= 8958) {
\$TAX = (\$TotEarn - 6042);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 8958 AND \$TotEarn <= 13542) {
\$TAX = (\$TotEarn - 8958);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 8958 AND \$TotEarn <= 13542) {
\$TAX = (\$TotEarn - 8958);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 13542 AND \$TotEarn <= 23958) {
\$TAX = (\$TotEarn - 13542);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 13542 AND \$TotEarn <= 23958) {
\$TAX = (\$TotEarn - 13542);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}

elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 1 AND \$TotEarn >= 23958 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 1 AND \$TotEarn >= 23958 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}

elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 0 AND \$TotEarn <= 4167) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 0 AND \$TotEarn <= 4167) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 4167 AND \$TotEarn <= 4583) {
\$TAX = (\$TotEarn - 4167);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 4167 AND \$TotEarn <= 4583) {
\$TAX = (\$TotEarn - 4167);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 4583 AND \$TotEarn <= 5417) {
\$TAX = (\$TotEarn - 4583);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 4583 AND \$TotEarn <= 5417) {
\$TAX = (\$TotEarn - 4583);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 5417 AND \$TotEarn <= 7083) {
\$TAX = (\$TotEarn - 5417);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 5417 AND \$TotEarn <= 7083) {
\$TAX = (\$TotEarn - 5417);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 7083 AND \$TotEarn <= 10000) {
\$TAX = (\$TotEarn - 7083);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 7083 AND \$TotEarn <= 10000) {
\$TAX = (\$TotEarn - 7083);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 10000 AND \$TotEarn <= 14583) {
\$TAX = (\$TotEarn - 10000);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 10000 AND \$TotEarn <= 14583) {
\$TAX = (\$TotEarn - 10000);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 14583 AND \$TotEarn <= 25000) {
\$TAX = (\$TotEarn - 14583);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 14583 AND \$TotEarn <= 25000) {
\$TAX = (\$TotEarn - 14583);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 2 AND \$TotEarn >= 25000 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 2 AND \$TotEarn >= 25000 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}

elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 0 AND \$TotEarn <= 5208) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 0 AND \$TotEarn <= 5208) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 5208 AND \$TotEarn <= 5625) {
\$TAX = (\$TotEarn - 5208);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 5208 AND \$TotEarn <= 5625) {
\$TAX = (\$TotEarn - 5208);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 5625 AND \$TotEarn <= 6458) {
\$TAX = (\$TotEarn - 5625);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 5625 AND \$TotEarn <= 6458) {
\$TAX = (\$TotEarn - 5625);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 6458 AND \$TotEarn <= 8125) {
\$TAX = (\$TotEarn - 6458);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 6458 AND \$TotEarn <= 8125) {
\$TAX = (\$TotEarn - 6458);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 8125 AND \$TotEarn <= 11042) {
\$TAX = (\$TotEarn - 8125);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 8125 AND \$TotEarn <= 11042) {
\$TAX = (\$TotEarn - 8125);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 11042 AND \$TotEarn <= 15625) {
\$TAX = (\$TotEarn - 11042);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 11042 AND \$TotEarn <= 15625) {
\$TAX = (\$TotEarn - 11042);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 15625 AND \$TotEarn <= 26042) {
\$TAX = (\$TotEarn - 15625);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 15625 AND \$TotEarn <= 26042) {
\$TAX = (\$TotEarn - 15625);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 3 AND \$TotEarn >= 26042 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 3 AND \$TotEarn >= 26042 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}

elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 0 AND \$TotEarn <= 6250) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 0 AND \$TotEarn <= 6250) {
\$TAX = (0.00);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 6250 AND \$TotEarn <= 6667) {
\$TAX = (\$TotEarn - 6250);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 6250 AND \$TotEarn <= 6667) {
\$TAX = (\$TotEarn - 6250);
\$TAX = (\$TAX * .05);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 6667 AND \$TotEarn <= 7500) {
\$TAX = (\$TotEarn - 6667);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 6667 AND \$TotEarn <= 7500) {
\$TAX = (\$TotEarn - 6667);
\$TAX = (20.83 + (\$TAX * .10));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 7500 AND \$TotEarn <= 9167) {
\$TAX = (\$TotEarn - 7500);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 7500 AND \$TotEarn <= 9167) {
\$TAX = (\$TotEarn - 7500);
\$TAX = (104.17 + (\$TAX * .15));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 9167 AND \$TotEarn <= 12083) {
\$TAX = (\$TotEarn - 9167);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 9167 AND \$TotEarn <= 12083) {
\$TAX = (\$TotEarn - 9167);
\$TAX = (354.17 + (\$TAX * .20));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 12083 AND \$TotEarn <= 16667) {
\$TAX = (\$TotEarn - 12083);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 12083 AND \$TotEarn <= 16667) {
\$TAX = (\$TotEarn - 12083);
\$TAX = (937.50 + (\$TAX * .25));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 16667 AND \$TotEarn <= 27083) {
\$TAX = (\$TotEarn - 16667);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 16667 AND \$TotEarn <= 27083) {
\$TAX = (\$TotEarn - 16667);
\$TAX = (2083.33 + (\$TAX * .30));
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 27083 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 27083 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');
}
else{
\$TAX_Ded = round(0.00);
}

``````

Thank you so much

First set your TAX to 0.00 and then remove all the round() and \$TAX_Ded. Do your adjustment and rounding after all the tax calculations.

Since you don’t add taxes till your TotEarn is greater than 2083 you would start at that point:

``````\$TAX = 0.00;

if(\$W4_STATUS == 1 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2083 AND \$TotEarn <= 2500) {
\$TAX = (\$TotEarn - 2083);
\$TAX = (\$TAX * .05);
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 0 AND \$TotEarn >= 2083 AND \$TotEarn <= 2500) {
\$TAX = (\$TotEarn - 2083);
\$TAX = (\$TAX * .05);
}

...

elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 16667 AND \$TotEarn <= 27083) {
\$TAX = (\$TotEarn - 16667);
\$TAX = (2083.33 + (\$TAX * .30));
}
elseif(\$W4_STATUS == 1 AND \$DEPENDENTS == 4 AND \$TotEarn >= 27083 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
}
elseif(\$W4_STATUS == 2 AND \$DEPENDENTS == 4 AND \$TotEarn >= 27083 AND \$TotEarn <= 50000) {
\$TAX = (5208.33);
}
else{
}

\$TAX .= 0.00001;
\$TAX = round(\$TAX, 2);
\$TAX_Ded = number_format(\$TAX, 2, '.', '');

``````