Re: How do i assign Integers only and not real numbers?

From: Date: Tue, 24 Sep 2002 01:54:44 +0000
Subject: Re: How do i assign Integers only and not real numbers?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117348@lists.php.net to get a copy of this message
Wouldn't round() work??? <? $year1 = 2002.75; $year1 = round($year1); echo $year1; // would round UP to 2003 $year2 = 2002.244415755; $year2 = round($year2); echo $year2; // would round DOWN to 2002 ?> Or, if you always want to round down, why not just split it on the decimal? <? $year3 = 2002.244415755; list($y,$d) = explode(".",$year3); echo $y; // would echo 2002 regardless of the decimals ?> Or as long as you're willing to give up year 10,000 compliance :), the year will "always" be the first four digits. <? $year4 = 2002.244415755; $year4 = substr($year4, 0, 4); echo $year4; // should echo the first 4 characters (2002) ?> Plenty of options :) I think I'd just use substr() Justin on 24/09/02 12:46 AM, Tom (tom.callaghan@claimnet.co.uk) wrote: > Hi all, > > I have a line of code that assigns a new year number: - > > $years = $years + ( $themonth / 12 ); > > but sometimes $years == 1998.0833333333 > > or > > $year == 2002.75 > > etc... > > I cant find anything like a round() or floor() function in PHP so that year > would be 1998 or 2002 only. > > Does anyone know what function would do this? Sorry if I`m wasting your > time if its a really obvious one! > > thanks in advance, > Tom > >

« previous php.general (#117348) next »