round
Round the body text (assumed to be a decimal numeric value)
to a given number of decimal places,
This filter takes one optional parameter.
If specified then the parameter's value will be taken to be the number
of decimal places to round the number up to.
If no decimal place parameter is provided then the value of the
"frac_digits" setting,
in the current Locale,
will be used.
If no decimal place parameter is provided,
and no "frac_digits" setting exists in the current
Locale,
then the number of decimal places will finally default to two.
|
Warning
If the body text contains non-digit characters
or contains more than one decimal point,
then the body text will be returned verbatim.
Note that a comma is considered to be a non-digit character.
|
|
Availability
This filter was introduced in version 5.5.0,
and is therefore not available for use with any earlier Interchange version.
|
Example
|
[filter round.1]123.45678[/filter]
|
Results in:
As warned above,
this filter will fail if the input contains non-digits.
Calling the "digits_dot" filter,
prior to the "round" filter,
will help guard against such a failure.
For example:
|
[filter digits_dot round.2]abc123 def.456ghi 78[/filter]
|
Which would result in:
Source code
sub {
my ($val, undef, $digits) = @_;
return round_to_frac_digits($val, $digits);
}
|