Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
rogue3
Regular
Regular


Joined: Jul 02, 2009
Posts: 63

PostPosted: Tue Nov 10, 2009 9:47 pm Reply with quote

Currently, my results page in my polls list the percentage out to the nearest hundreth. I'd like to round it to a whole number.

Here is the code for the percentage in the Survey index file:

Code:
      if($sum) {

          $percent = 100 * $optionCount / $sum;
      } else {
          $percent = 0;


Can anyone help me add the necessary code to round that value?

There is also code that prints the value that might be the one to adjust:

Code:
                printf(" %.2f%%", $percent);


Last edited by rogue3 on Tue Nov 10, 2009 9:48 pm; edited 1 time in total 
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Tue Nov 10, 2009 9:48 pm Reply with quote

Use the round() function Smile

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
rogue3
PostPosted: Tue Nov 10, 2009 9:51 pm Reply with quote

Wow, fast reply!

I thought I'd tinker around with it a bit for a little trial and error and I think I might have found the fix.

I changed
Code:
                printf(" %.2f%%", $percent);


to
Code:
                printf(" %.0f%%", $percent);


It appears like it is working, as my results now are whole numbers Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©