XtScript Function: round
Rounds up or down a floating point number.
round is a function in XtScript that can process floating number and round it up or down and return the result.
XtScript round function basic syntax:
<!--parser:xtscript--> call round $num=...; $mode=...; $precision=... <!--/parser:xtscript-->
Optional available arguments in XtScript round function:
- $mode
Determine how the half (.5) will be rounded.
Value:
• PHP_ROUND_HALF_UP (default). Round .5 up.
• PHP_ROUND_HALF_DOWN. Round .5 down.
• PHP_ROUND_HALF_EVEN. Round .5 to the even number.
• PHP_ROUND_HALF_ODD. Round .5 to the odd number. - $precision
Determine the number of decimal digits to round to.
Value: (number)
Learn XtScript round function from examples
Round floating numbers using XtScript round function
- Code:<!--parser:xtscript--> var $number = 7125.64559 var $number_2 = 14.55 # Round number to two floating decimal var $tdf = call round $num=$number; $precision=2 # The precision can also be a negative number which will round number beyond the floating decimal var $neg_tdf = call round $num=$number; $precision=-2 print Number: $number <br/> print Rounded two floating digit: $tdf <br/> print Rounded beyond the floating decimal: $neg_tdf print <br/><br/> print Second number: $number_2 <br/> print Round second number half to odd: call round $num=$number_2; $mode=PHP_ROUND_HALF_ODD; $precision=1 print <br/> print Round second number half to even: call round $num=$number_2; $mode=PHP_ROUND_HALF_EVEN; $precision=1 <!--/parser:xtscript-->- Result:
Number: 7125.64559
Rounded two floating digit: 7125.65
Rounded beyond the floating decimal: 7100
Second number: 14.55
Round second number half to odd:14.5
Round second number half to even:14.6
Rounded two floating digit: 7125.65
Rounded beyond the floating decimal: 7100
Second number: 14.55
Round second number half to odd:14.5
Round second number half to even:14.6
Last edited on