Well, after calculating the percentages (and before outputting them), use an if statement to see if their sum is 100. If it's not, add the difference to the highest percentage.
Something like:
$percent1 = 50;
$percent2 = 49.9;
if ($percent1 + $percent2 != 100) {
$percent1 += 100 - ($percent1 + $percent2);
}
Of course, my code is really simplified in that I didn't find the largest percentage, but I'm sure you can do that...
Diego