Re: percentage problems

From: Date: Sat, 22 Sep 2001 21:53:44 +0000
Subject: Re: percentage problems
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-68368@lists.php.net to get a copy of this message
Thanks for that. Assigning a type to that variable never even occured to me. :-) Tyler ----- Original Message ----- From: "Matt Greer" <tortus@rcnchicago.com> To: "Tyler Longren" <tyler@captainjack.com>; "PHP-General" <php-general@lists.php.net> Sent: Saturday, September 22, 2001 4:52 PM Subject: Re: [PHP] percentage problems > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#68368) next »