Re: Rounding numbers with respect to percentages

From: Date: Mon, 28 Apr 2003 18:15:46 +0000
Subject: Re: Rounding numbers with respect to percentages
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19692@lists.php.net to get a copy of this message
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

« previous php.windows (#19692) next »