round: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{MacroFunction
{{MacroFunction
|name=round
|name=round
|description=Returns the rounded value of a number to   specified precision     (number of digits after the decimal point).   precision can be zero (default).
|description=
Returns the rounded value of a number to specified precision (number of digits after the decimal point). Precision can be zero (default).


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: result = round(value, precision)]
[h: result = round(value, precision)]
</source>
</syntaxhighlight>
'''Parameters'''
{{param|value|Input value to round.}}
{{param|precision|Number of decimal places to retain. Default is 0.}}


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>[r: round(1.45)]
[r: round(1.45)]
</syntaxhighlight>
</source>
Returns 1
Returns 1


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: round(1.45, 1)]
[r: round(1.45, 1)]
</source>
</syntaxhighlight>
Returns 1.5
Returns 1.5


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: round(1.44,1)]
[r: round(1.44,1)]
</source>
</syntaxhighlight>
Returns 1.4
Returns 1.4
}}
}}
[[Category:Mathematical Function]]
[[Category:Mathematical Function]]

Revision as of 17:07, 12 March 2021

round() Function

Returns the rounded value of a number to specified precision (number of digits after the decimal point). Precision can be zero (default).

Usage

[h: result = round(value, precision)]

Parameters

  • value - Input value to round.
  • precision - Number of decimal places to retain. Default is 0.

Examples

[r: round(1.45)]

Returns 1

[r: round(1.45, 1)]

Returns 1.5

[r: round(1.44,1)]
Returns 1.4