public function round($value, $rule, array $params = array())
{
$format = $this->get($rule);
// prepare params
$params = array_merge(array('roundType' => null, 'roundValue' => null), $params);
// get vars
$roundType = $params['roundType'];
$roundValue = $params['roundValue'];
if (!$roundType) {
$roundType = array_key_exists('round_type', $format) ? $format['round_type'] : self::ROUND_NONE;
}
if (null === $roundValue) {
$roundValue = array_key_exists('round_value', $format) ? $format['round_value'] : self::ROUND_DEFAULT;
}
$roundValue = (int) $roundValue;
if (self::ROUND_CEIL === $roundType) {
$base = pow(10, $roundValue);
$value = ceil($value * $base) / $base;
} elseif (self::ROUND_CLASSIC === $roundType) {
$value = round($value, $roundValue);
} elseif (self::ROUND_FLOOR === $roundType) {
$base = pow(10, $roundValue);
$value = floor($value * $base) / $base;
} elseif (self::ROUND_NONE === $roundType) {
$value = round($value, Formatter::ROUND_DEFAULT);
// hack, because 123.400000001 !== 123.4
} else {
throw new Exception('Undefined round mode: "' . $roundType . '"');
}
return $value;
}