Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round of number 1

Status
Not open for further replies.

alexmooij

Programmer
Dec 24, 2004
1
NL
Hi,

it probably is very stupid but here it goes:

I have a read filesize of e.g. 203.839453409834 KB in $final_size. I want to round of the number to in this case,
204 KB. I tried splitting the var at the point into @ARRAY and then display @ARRAY[0] but that does not work.

This is what I did:

$final_read = $bytes_read/1024;
@ARRAY = split(/./,$final_read);
$final_read = @ARRAY[0];

When I try to display $final_read it is empty. Please help.
 
There's a perl function called [tt]int()[/tt] that returns the integer portion of a number
Code:
$x = 1.75;

$y = int ($x); # $z will = 1
If you want to round to the nearest integer, rounding up fractions of 0.5 or greater, do this:
Code:
$z = int ($x + 0.5);  # $z will = 2

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top