Forum Moderators: coopster

Message Too Old, No Replies

int function to float

         

nanat

10:32 am on Feb 17, 2010 (gmt 0)

10+ Year Member




function deduction()
{
include("connect.php");
$result = odbc_exec($conn,"select t0.emp_id,t0.amount,t1.id,t1.name,t2.name,t1.updcode from paytrnh t0
inner join trans t1 on t0.tran_id = t1.id
inner join person t2 on t0.emp_id = t2.id
where t0.emp_id ='837496' and t0.pay_date = '02/02/2010' and t1.updcode ='D'
");

if($result > 0)
{
$rdata = '<table cellpadding="2" cellspacing="2">';
$counter = 0;
while (odbc_fetch_array($result))
{
$Dname = odbc_result($result,4);
$amount = number_format(odbc_result($result,2),2);

$rdata .= '<tr><td>'.$Dname.'<td> <td>'.$amount.'</td>';
}
$rdata .='</tr></table>';
}
return $rdata;
}


i trying to add two int function but it doesn't work.
what's wrong with my code?

$a = floatval(getTotalearning());
$b = floatval(getTotaldeduction());
$c = 0;

echo $c=($a)-($b);

return $b only;

it doesn't subtract what wrong with my code?

jatar_k

2:11 pm on Feb 17, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



have you echo'ed those values to see exactly what is contained in them as you go along?

nanat

1:42 am on Feb 18, 2010 (gmt 0)

10+ Year Member



yes jatar_k i echo the result:

$a = floatval(getTotalearning()); = 6,631.07
$b = floatval(getTotaldeduction()); = 616.52

echo $c=($a)-($b);

it will return 616.52 but the code ignore $a;

Readie

2:12 am on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



6,631.07

There's a comma as your thousands seperator, but PhP is probably not realising it's intended as a thousands seperator - try this:

$a = floatval(getTotalearning());
$a = preg_replace('/,/', '', $a);

$b = floatval(getTotaldeduction());
$b = preg_replace('/,/', '', $b);

$c = $a - $b;
echo number_format($c, '2', '.', ',');

nanat

2:45 am on Feb 18, 2010 (gmt 0)

10+ Year Member



tnx ready i get it ^^

$string= array(',');
$areYou= array(getTotalearning(),getTotaldeduction());
$awee = str_replace( $string,'', $areYou);
$a=$awee[0];
$b=$awee[1];
echo number_format($c=$a-$b,2);