Forum Moderators: coopster

Message Too Old, No Replies

how to use function round in php expressions

php expressions round function database filesize

         

halloweb

2:31 pm on Sep 28, 2004 (gmt 0)

10+ Year Member


$total=round(($d->Data_length+$d->Index_length)/1024,1);

that code above is how to get the amount of Kb of a certain table in your db

this code below calculates total amount (=filesize) of a certain database

problem for me here:

how to use round in the expression below (as in the example given above)

$total = $row['Data_length']+$row['Index_length'];

jatar_k

6:43 pm on Sep 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, since the function works as such

float round ( float val [, int precision])

and you have
$total = $row['Data_length']+$row['Index_length'];

if you want to round the value after the addition then this would work, I set the precision to 2

$total = round($row['Data_length']+$row['Index_length'],2);

or if you wanted to round each one before the addition, again each precision 2

$total = round($row['Data_length'],2)+round($row['Index_length'],2);

halloweb

7:04 pm on Sep 28, 2004 (gmt 0)

10+ Year Member


what do you mean with precision 2
is that to be understood as

let's say 2,45 Kb ---> rounded as integer 2?

jatar_k

7:09 pm on Sep 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



[php.net...]

float round ( float val [, int precision])

precision is the second parameter for the function

Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

halloweb

7:12 pm on Sep 28, 2004 (gmt 0)

10+ Year Member


$total = round($row['Data_length'],2)+round($row['Index_length'],2);

you didn't tell me (if possible)
what to do with this below : where do I put my divide by 1024 to get my kbs?

/1024

halloweb

7:16 pm on Sep 28, 2004 (gmt 0)

10+ Year Member


$total = round($row['Data_length']+$row['Index_length']/1024,2);