Fix division by zero in Icinga\Util\Format

refs #6125
This commit is contained in:
Johannes Meyer 2014-05-06 08:32:42 +02:00
parent dd3e406052
commit 2f911f75a1
1 changed files with 9 additions and 4 deletions

View File

@ -153,14 +153,19 @@ class Format
$value = abs($value); $value = abs($value);
$sign = '-'; $sign = '-';
} }
$pow = floor(log($value, $base));
$result = $value / pow($base, $pow); if ($value == 0) {
$pow = $result = 0;
} else {
$pow = floor(log($value, $base));
$result = $value / pow($base, $pow);
}
// 1034.23 looks better than 1.03, but 2.03 is fine: // 1034.23 looks better than 1.03, but 2.03 is fine:
if ($pow > 0 && $result < 2) { if ($pow > 0 && $result < 2) {
$pow--; $result = $value / pow($base, --$pow);
$result = $value / pow($base, $pow);
} }
return sprintf( return sprintf(
'%s%0.2f %s', '%s%0.2f %s',
$sign, $sign,