Re: percentage problems

From: Date: Sat, 22 Sep 2001 21:52:30 +0000
Subject: Re: percentage problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68367@lists.php.net to get a copy of this message
On Saturday 22 September 2001 16:41, you wrote: > Hello all, > > I'm having some troubles making correct percentages. > > I'm writing a simple poll system. Is there an easy way to generate > percentages? I know to divide and all that good stuff. I do substr to get > rid of the decimals, but sometimes the percentages still aren't displayed > correctly. How do you people usually go about doing percentages? Better than substr is to cast the variable to be an int (int)$firstpercent would force the variable to be an integer, chopping off any decimals it may have. Other than that I don't really know what to say. Determining percentage is more a math thing than php. Maybe take a look at other poll scripts out there (there's tons of them). Keep in mind both substr and casting to an integer are essentially always rounding down. So if your values are 58.9, 12.6, and 28.5 then you'll lose 2 percent after all is said and done. Matt

« previous php.general (#68367) next »