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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Always round to the next value

Status
Not open for further replies.

NateBro

Programmer
Sep 1, 2004
233
US
i want to round 1.2 to 2. and 1.5 to 2.

if the number is a decimal always round it to the next whole number.

how would i do this?

thanks you for your time :D
 
hmmmmm....

i don't think i know how to do that "int()", could you give an example of what that would look like?


thanks,

Nate_Bro
 
ok sorry i got ya, $end_page = int($end_page + 1);

thank you
 
Or you could use the ceil() function in the standard POSIX module:
Code:
use POSIX;
$end_pge = POSIX::ceil( $end_page );
 
Sorry for the double-post - hit submit too early.
POSIX::ceil is recommended above using int - see the entry for int() in perlfunc for more.
 
The use of INT in this case is acceptable as you want it to round down to the integer number.
To use INT as a true rounding function - add 0.49 to the value.
This is a work round as POSIX::ceil is not always available.

Keith
 
audiopro (Programmer) 30 Apr 05 8:55
The use of INT in this case is acceptable as you want it to round down to the integer number.
To use INT as a true rounding function - add 0.49 to the value.

will it still come out as a whole number then or a decimal?
 
3.3 + 0.49 = 3.79
INT(3.79) = 3

3.7 +0.49 = 4.19
INT(4.19) = 4

if the decimal > 0.5 It is rounded up.
if the decimal <=0.5 It is rounded down.

We are using INT to simply chop the decimal point and the decimal digits off the end of the number as if we were manipulating a string.


Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top