Round ViewHelper <f:round>
The RoundViewHelper rounds a float value with the specified precision and rounding mode.
The ViewHelper mimics PHP's round
function.
rounding modes | PHP < 8.4 | PHP >= 8.4 |
---|---|---|
HalfAwayFromZero | Yes | Yes |
HalfTowardsZero | Yes | Yes |
HalfEven | Yes | Yes |
HalfOdd | Yes | Yes |
TowardsZero | No | Yes |
AwayFromZero | No | Yes |
NegativeInfinity | No | Yes |
PositiveInfinity | No | Yes |
Examples
Round with default precision
<f:round value="123.456" />
Copied!
123.46
Copied!
Round with specific precision
<f:round value="123.456" precision="1" />
Copied!
123.5
Copied!
Round with specific precision and rounding mode
<f:round value="123.456" precision="1" roundingMode="HalfAwayFromZero" />
Copied!
123.5
Copied!
Tag content as value
<f:round precision="1">123.456</f:round>
Copied!
123.5
Copied!
Go to the source code of this ViewHelper: RoundViewHelper.php (GitHub).
Arguments
The following arguments are available for the round ViewHelper:
precision
-
- Type
- int
- Default
- 2
Rounding precision
roundingMode
-
- Type
- string
- Default
- 'HalfAwayFromZero'
Rounding mode
value
-
- Type
- float
The number that should be rounded