Wordpress: Calculate font-size in Tag Cloud

$fontSizeUnits = "px";
$fontSizeMin = 15;
$fontSizeMax = 50;
$maxValue = 12;
$minValue = 1;

where $results is MySQL result set.

foreach ($results as $result) {
$tag = $result->name;
$tagURI = get_option('home') . '/' . $result->taxonomy . '/' . $result->slug . '/';
$count = $result->count;
$weight = ( $count - $minValue ) / ( $maxValue - $minValue );
$fontSize = $fontSizeMin + round( ($fontSizeMax - $fontSizeMin) * $weight );
echo "<li style='display: inline-block; font-size:". $fontSize. $fontSizeUnits."'><a href=".$tagURI." title='(".$count." posts)'>".$tag."</a></li>";
}