ok, I will try this.
Thank you so much
ok, I will try this.
Thank you so much
Flat round it.
Round(<number> * 100) / 100
So if the number is 216.155:
Number * 100 = 21615.5
Flat round: 21616
Divide: 216.16
Instead of using comparison statements (if and elseif) you could also use database, which I believe will make it easier to maintain.
Here’s how:
First get all your calculation reference values
(W4_STATUS, DEPENDENTS, more than TotEarn, less than TotEarn, deduction, tax rate)
and put them in a plain text file
I have done that so all you need to do is to verify the values -
tax.txt:
1 0 0 2083 0 0.00
1 0 2083 2500 2083 0.00 .05
1 0 2500 3333 2500 20.83 .10
1 0 3333 5000 3333 104.17 .15
1 0 5000 7917 5000 354.17 .20
1 0 7917 12500 7917 937.50 .25
1 0 12500 22917 12500 2083.33 .30
1 0 22917 50000 0 5208.33
1 1 0 3125 0 0.00
1 1 3125 3542 3125 0.00 .05
1 1 3542 4375 3542 20.83 .10
1 1 4375 6042 4375 104.17 .15
1 1 6042 8958 6042 354.17 .20
1 1 8958 13542 8958 937.50 .25
1 1 13542 23958 13542 2083.33 .30
1 1 23958 50000 0 5208.33
1 2 0 4167 0 0.00
1 2 4167 4583 4167 0.00 .05
1 2 4583 5417 4583 20.83 .10
1 2 5417 7083 5417 104.17 .15
1 2 7083 10000 7083 354.17 .20
1 2 10000 14583 10000 937.50 .25
1 2 14583 25000 14583 2083.33 .30
1 2 25000 50000 0 5208.33
1 3 0 5208 0 0.00
1 3 5208 5625 5208 0.00 .05
1 3 5625 6458 5625 20.83 .10
1 3 6458 8125 6458 104.17 .15
1 3 8125 11042 8125 354.17 .20
1 3 11042 15625 11042 937.50 .25
1 3 15625 26042 15625 2083.33 .30
1 3 26042 50000 0 5208.33
1 4 0 6250 0 0.00
1 4 6250 6667 6250 0.00 .05
1 4 6667 7500 6667 20.83 .10
1 4 7500 9167 7500 104.17 .15
1 4 9167 12083 9167 354.17 .20
1 4 12083 16667 12083 937.50 .25
1 4 16667 27083 16667 2083.33 .30
1 4 27083 50000 0 5208.33
2 0 2083 2500 2083 0 .05
2 0 2500 3333 2500 20.83 .10
2 0 3333 5000 3333 104.17 .15
2 0 5000 7917 5000 354.17 .20
2 0 7917 12500 7917 937.50 .25
2 0 12500 22917 12500 2083.33 .30
2 0 22917 50000 0 5208.33
2 1 0 3125 0 0.00
2 1 3125 3542 3125 0.00 .05
2 1 3542 4375 3542 20.83 .10
2 1 4375 6042 4375 104.17 .15
2 1 6042 8958 6042 354.17 .20
2 1 8958 13542 8958 937.50 .25
2 1 13542 23958 13542 2083.33 .30
2 1 23958 50000 0 5208.33
2 2 0 4167 0 0.00
2 2 4167 4583 4167 0.00 .05
2 2 4583 5417 4583 20.83 .10
2 2 5417 7083 5417 104.17 .15
2 2 7083 10000 7083 354.17 .20
2 2 10000 14583 10000 937.50 .25
2 2 14583 25000 14583 2083.33 .30
2 2 25000 50000 0 5208.33
2 3 0 5208 0 0.00
2 3 5208 5625 5208 0.00 .05
2 3 5625 6458 5625 20.83 .10
2 3 6458 8125 6458 104.17 .15
2 3 8125 11042 8125 354.17 .20
2 3 11042 15625 11042 937.50 .25
2 3 15625 26042 15625 2083.33 .30
2 3 26042 50000 0 5208.33
2 4 0 6250 0 0.00
2 4 6250 6667 6250 0.00 .05
2 4 6667 7500 6667 20.83 .10
2 4 7500 9167 7500 104.17 .15
2 4 9167 12083 9167 354.17 .20
2 4 12083 16667 12083 937.50 .25
2 4 16667 27083 16667 2083.33 .30
2 4 27083 50000 0 5208.33
Next create a database. Use sqlite if your PHP is version 5; if not then use MySQL or any database that is available to you.
Here is a simple sqlite script to create a database and insert those values above.
create_table.php
<?php
$table = new SQLiteDatabase("tax.sqlite");
$table->query("CREATE TABLE tax".
" ( txid INTEGER PRIMARY KEY,Status INTEGER, Dependents INTEGER,More INTEGER,Less INTEGER,Deduction CHAR,Tax Char,Rate CHAR )");
$data = explode("\
",@file_get_contents("tax.txt"));
$num = count($data);
for($ix=0;$ix<$num;$ix++)
{
$items = explode(" ",$data[$ix]);
if(!$items[0]) continue;
$ins++;
$table->query("INSERT INTO tax VALUES(NULL,'$items[0]','$items[1]','$items[2]','$items[3]','$items[4]','$items[5]','$items[6]')");
}
echo "Tax table created and $ins records added";
?>
Now the tax calculation values are ready to be used for your function.
Here is an example of the script (tax.php):
<?php
$status = $_POST['W4_STATUS'];
$dependents = $_POST['DEPENDENTS'];
$earning = $_POST['TotEarn'];
echo '
<form method="post" action="tax.php">
W4_STATUS: <input name="W4_STATUS" value="'.$status.'"/><br/><br/>
DEPENDENTS: <input name="DEPENDENTS" value="'.$dependents.'"/><br/><br/>
TotEarning: <input name="TotEarn" value="'.$earning.'"/><br/><br/>
<input type="submit" name="tax" value="Compute"/>
</form>
';
if($_POST['tax'])
{
$tax = new SQLiteDatabase("tax.sqlite");
$q = $tax->query("SELECT Deduction,Tax,Rate FROM tax WHERE Status='$status' and Dependents='$dependents' and More < '$earning' and Less > '$earning'");
if($q)
{
list($deduction,$tax,$rate) = $q->fetch();
$taxable = 0;
if($deduction) $taxable = ($earning - $deduction) * $rate;
$tax += $taxable+.0001; // adjust for rounding up
echo "<h3>Your amount tax due is $".round($tax,2)."</h3>";
}
else echo "Database Error...";
}
?>
Click on the link below to test the above script:
http://w-cms.org/sqlite/tax.php
this post #20 solves my problem.
Thank you