Variable and Value Types

hay all, hope somone can help me to find the problem,
i try to build a reppot in my site , using mysql database and php
i have an array ($row) that hold the data from mysql table and i have two columns that i need to change there format beffore making my calcuation in the reported ,

$row[‘DS’] //comes as number with 1 point (like 12.2) --> i need to change it to integer wihtout point
$row[‘TC’] // comes as number with 1 point (like 12.2) --> no need to change

and then the calcultion: $row[‘TC’]/$row[‘DS’] // when i doing the calculation im getting a vlaue with around 16 number after the points (like 12.34454354444334) --> i want to see only two number after the point

im try to do it in that way

$DSF = number_format($row[‘DS’],0);
$ConF = ($row[‘TC’] / $DSF) ;
echo $ConF

but there is a problem with that way fro example
$row[‘TC’] = 190.0
$row[‘DS’] = 59009.2 //after chainging the format it will be 59009
and then the calculation should be 59009/190 = 000.321 (somthing around this)
but instend of this i gote 3.22

in this case the values should be 0

someone can help me with this

this the right result for 59009 divided by 190 = 310.57368421053

Try one of these functions

[php]
//round var to two decimal places
round($var,2);

round ($row[‘DS’]);
intval ($row[‘DS’]);
floor ($row[‘DS’]);
[/php]

[php]
$tc = ‘190.0’;
$ds = round(‘59009.2’);

// $ds now = to 59009

$result = round($ds/$tc,2);

echo 'result = '.$result;
//result = 310.57368421053
//result = 310.57
[/php]

round to 2 decimals

[php]

<?php $tc = '190.0'; $ds = round('59009.2'); echo 'ds = '$ds.'
'; $result = round($ds/$tc,2); echo 'result = '.$result; ?>

ds = 59009
result = 310.57
[/php]

But 190/59009 = 0.003******
but if you round the result you will get 0

[php]<?php

$tc = ‘190.0’;
$ds = round(‘59009.2’);
// ds = 59009

echo $ds.’
’;

$result = $tc/$ds;
$result = round($result);
// result = 0
echo 'result = '.$result;

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service