Thanks for that.  Assigning a type to that variable never even occured to
me.  :-)

Tyler

----- Original Message -----
From: "Matt Greer" <[EMAIL PROTECTED]>
To: "Tyler Longren" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to