Round (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (remove Mods reference)
 
(36 intermediate revisions by 6 users not shown)
Line 1: Line 1:
This [[Intrinsic Classes|intrinsic]] function returns a floating point number that is the
{{Template:Float:Round subtitle}}
method object number rounded to a specified number of decimal places.


The Round function is available as of version 7.6 of the [[Sirius Mods]].
The <var>Round</var> [[Intrinsic classes|intrinsic]] function returns a floating point number that is the method object number rounded to a specified number of decimal places.
===Round syntax===
 
  %num = number:Round(dp)
==Syntax==
====Syntax terms====
{{Template:Float:Round syntax}}
<dl>
 
<dt>%num
===Syntax terms===
<dd>A variable to receive the floating point result.
<table class="syntaxTable">
<dt>number
<tr><th>%number</th>
<dd>A Float value to be rounded to the number of decimal places specified
<td>A variable to receive the floating point result. </td></tr>
in the method argument, ''dp''.
 
<dt>dp
<tr><th>float</th>
<dd>A numeric value that specifies the number of decimal places
<td>A <var>Float</var> value to be rounded to the number of decimal places specified in the method argument, <var class="term">dp</var>. </td></tr>
to which the input number is rounded.
 
This value defaults to 0, and it must be between 0 and 75.
<tr><th>dp</th>
</dl>
<td>A numeric value that specifies the number of decimal places to which the input number is rounded. This value defaults to 0, and it must be between 0 and 75.</td></tr>
===Usage Notes===
</table>
*Negative numbers are rounded down to the nearest integer; positive numbers are rounded up.
 
===Examples===
==Usage notes==
The following program demonstrates the Round method.
<ul>
  begin
<li>Negative numbers are rounded down to the nearest integer; positive numbers are rounded up. </li>
</ul>
 
==Examples==
The following program demonstrates the <var>Round</var> method.
<p class="code">begin
   [[PrintText statement|printText]] {~} = {3.1415926:round}
   [[PrintText statement|printText]] {~} = {3.1415926:round}
   printText {~} = {3.1415926:round(0)}
   printText {~} = {3.1415926:round(0)}
   printText {~} = {3.1415926:round(1)}
   printText {~} = {3.1415926:round(1)}
   printText {~} = {3.1415926:round(4)}
   printText {~} = {3.1415926:round(4)}
  end
end
</p>
The result is:
The result is:
  3.1415926:round = 3
<p class="output">3.1415926:round = 3
  3.1415926:round(0) = 3
3.1415926:round(0) = 3
  3.1415926:round(1) = 3.1
3.1415926:round(1) = 3.1
  3.1415926:round(4) = 3.1416
3.1415926:round(4) = 3.1416
 
</p>
===See also===
[[List of Intrinsic Float Methods]]


[[Category:Intrinsic Float methods]]
==See also==
[[Category:Intrinsic methods]]
{{Template:Float:Round footer}}
[[Category:System methods]]

Latest revision as of 22:38, 22 May 2017

Round a floating point number to specified decimal places (Float class)


The Round intrinsic function returns a floating point number that is the method object number rounded to a specified number of decimal places.

Syntax

%number = float:Round[( [dp])]

Syntax terms

%number A variable to receive the floating point result.
float A Float value to be rounded to the number of decimal places specified in the method argument, dp.
dp A numeric value that specifies the number of decimal places to which the input number is rounded. This value defaults to 0, and it must be between 0 and 75.

Usage notes

  • Negative numbers are rounded down to the nearest integer; positive numbers are rounded up.

Examples

The following program demonstrates the Round method.

begin printText {~} = {3.1415926:round} printText {~} = {3.1415926:round(0)} printText {~} = {3.1415926:round(1)} printText {~} = {3.1415926:round(4)} end

The result is:

3.1415926:round = 3 3.1415926:round(0) = 3 3.1415926:round(1) = 3.1 3.1415926:round(4) = 3.1416

See also