Hmm, I don't know that I made myself clear, so I will go into more detail to make sure we are on the same page.
The users vote for which search engine they used to find site. (Google, Yahoo, Bing)
The votes are stored in database as total votes for EACH search engine (Google=30,Yahoo=23,Bing=13)
Then, I am figuring out the percentage of each search engine used by dividing by total number of votes ($searchEngine/$totalVotes*100) which of course does not always yield nice results.
This number ($google,$yahoo,$bing) is then rounded. The problem of course is that sometimes the 3 different percentages don't add up to 100%.
Derek | [reply] |
Your made yourself clear enough in the OP but you don't seem to like the answers (or won't understand them?).
The numbers in your latest post, 30, 23, and 13, happen to be what I gather your mean by a "nice" case; that is, when calculated as percentages of their total and rounded, the percentages add up (nicely) to 100.
Here's a case where the numbers are not "nice" and where a disclaimer is the only reasonable solution (fudging is NOT, IMO, reasonable):
#!/usr/bin/perl
use strict;
use warnings;
#785290
my $Google=30; my $Yahoo=23; my $Bing=12;
my $sum=$Google + $Yahoo + $Bing;
my $google_percent = $Google/$sum;
print "G: $google_percent";
my $yahoo_percent = $Yahoo/$sum;
print "\tY: $yahoo_percent";
my $bing_percent = $Bing/$sum;
print "\tB: $bing_percent \n";
my $total = ($google_percent + $yahoo_percent + $bing_percent);
my $roundedG = sprintf("%.2f", $google_percent);
my $roundedY = sprintf("%.2f", $yahoo_percent);
my $roundedB = sprintf("%.2f", $bing_percent);
my $rounded = sprintf("%.2f", $total);
print "Google: $roundedG; Yahoo: $roundedY; Bing: $roundedB; Total: $r
+ounded \n";
printf ('%.0f', (($Google/$sum)*100));
print "%\n";
printf ('%.0f', (($Yahoo/$sum)*100));
print "%\n";
printf ('%.0f', (($Bing/$sum)*100));
print "%\n";
print $rounded*100 . "% (Percentages may not add up to 100 because of
+rounding errors!)\n";
| [reply] [d/l] |
| [reply] |
Ok. This is my first time to ever post on this board, and I may not know as much as you all do, which is why I posted here in the first place, to seek others' greater knowledge so that I might learn from them. I'm sorry if I sounded like I didn't LIKE any answers, because I assure you that was not the case. I just wanted to make sure that I made myself clear, as I wasn't sure that I had.
After the replies you have shared with me, I will go with disclaimer.
Derek
| [reply] |