Re: Rounding numbers with respect to percentages
| From: | Ignatius Reilly | Date: | Mon, 28 Apr 2003 18:26:26 +0000 |
| Subject: | Re: Rounding numbers with respect to percentages | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-19694@lists.php.net to get a copy of this message | ||
Sorry Ron, I meant
33.33
33.33
33.34
It's been a long day...
Ignatius
____________________________________________
----- Original Message -----
From: "Ignatius Reilly" <ignatius.reilly@free.fr>
To: "Herhuth, Ron" <Ron.Herhuth@tatumpartners.com>;
<php-windows@lists.php.net>
Sent: Monday, April 28, 2003 8:15 PM
Subject: Re: [PHP-WIN] Rounding numbers with respect to percentages
> You can't - directly, that is.
>
> classical example:
>
> 33.3
> 33.3
> 33.4
> each rounds up to 33.3, total 99.9
>
> The only way is to define the nth number as 100.0-sum( round( a(1), 1 )
...
> round( a(n-1), 1 ) )
>
> Ignatius
> HTH
> ____________________________________________
> ----- Original Message -----
> From: "Herhuth, Ron" <Ron.Herhuth@tatumpartners.com>
> To: <php-windows@lists.php.net>
> Sent: Monday, April 28, 2003 7:52 PM
> Subject: [PHP-WIN] Rounding numbers with respect to percentages
>
>
>
> I am trying to dynamically calculate percentages and return the results
> rounded off to the first decimal place. I tried using the
>
> "round($num,1) " -- but the results don't always add up to 100%
> "intval($num)" -- doesn't account for percentages that are less than 1
> "floatval($num) -- doesn't allow me to round off to a specificed decimal
> place, which in return gets me back to the same problem as "round"
>
> How can I round off to the first decimal place making sure they add up to
> 100%?
>
> Thanks,
> Ron
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>