logo
Home XtGem- Templates- XtScript- bottom
XtGemmanual

XtScript functions

round

Rounds up or down a floating point number

Syntax

[var $... = ]call round $num=…[;$mode=…][;$precision=…][...] optional · ... your value

Notes

$precision = The optional number of decimal digits to round to.
$mode = what happens to a half(.5)
one of the following
PHP_ROUND_HALF_UP ; default action
PHP_ROUND_HALF_DOWN
PHP_ROUND_HALF_EVEN ; round to the even number
PHP_ROUND_HALF_ODD ; round to the odd number

Example

<!--parser:xtscript-->
var $input = 12345.55
var $precision=1
var $output = call round $num=$input; $precision=$precision
print input = $input<br />
print output = $output<hr />

var $input = 12345.55
var $precision=-3
var $output = call round $num=$input; $precision=$precision
print input = $input<br />
print output = $output<hr />
  
var $input = 12345.55
var $precision=1
var $mode=PHP_ROUND_HALF_DOWN
var $output = call round $num=$input; $mode=$mode; $precision=$precision
print input = $input<br />
print output = $output
<!--/parser:xtscript-->

Copy as text

Output reload

input = 12345.55
output = 12345.6
input = 12345.55
output = 12000
input = 12345.55
output = 12345.5

Related

ceil floor

XtGem manual · all sections

Powered by XtGem
About us Contact Forum top