[PHP] rounding average to one decimal point
Hi, I have a randon group of numbers I need the average of. When I add them up and divide by how many there are and print the result, I get a lot of decimal places. The number comes out to look like 29.3529411765, but I don't need that many decimal places. rounding to one decimal place will be fine. anyway to trim off the excess decimal values? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] rounding average to one decimal point
Hello Adam, Monday, May 10, 2004, 7:03:36 PM, you wrote: AW Hi, I have a randon group of numbers I need the average of. When I add AW them up and divide by how many there are and print the result, I get a AW lot of decimal places. The number comes out to look like 29.3529411765, AW but I don't need that many decimal places. rounding to one decimal place AW will be fine. anyway to trim off the excess decimal values? Try the round() function? :) ceil() and floor() might help if you decide you don't want the extra decimal places too. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] rounding average to one decimal point
How about round() echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 http://www.phpbuilder.com/manual/function.round.php Hi, I have a randon group of numbers I need the average of. When I add them up and divide by how many there are and print the result, I get a lot of decimal places. The number comes out to look like 29.3529411765, but I don't need that many decimal places. rounding to one decimal place will be fine. anyway to trim off the excess decimal values? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] rounding average to one decimal point
On Mon, 10 May 2004, Richard Davey wrote: Hello Adam, Monday, May 10, 2004, 7:03:36 PM, you wrote: AW Hi, I have a randon group of numbers I need the average of. When I add AW them up and divide by how many there are and print the result, I get a AW lot of decimal places. The number comes out to look like 29.3529411765, AW but I don't need that many decimal places. rounding to one decimal place AW will be fine. anyway to trim off the excess decimal values? Try the round() function? :) ceil() and floor() might help if you decide you don't want the extra decimal places too. i didn't know about round(), guess i should check php.net/round next time ;) thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php