Difference between revisions of "$round"

From Scriptwiki
Jump to: navigation, search
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
* ''N'' is the number you want to round.
 
* ''N'' is the number you want to round.
* ''D'' is the number of decimals you want. If no ''D'' is supplied it will assume 0.
+
* ''D'' is the number of decimals you want.
  
 
== Examples ==
 
== Examples ==
Line 10: Line 10:
 
The following will echo pi with 3 decimals:
 
The following will echo pi with 3 decimals:
  
/[[Echo|echo -a]] Pi: $round([[$pi]],3)
+
  $round([[$pi]],3) ;will return ''3.142''
 +
  $round(1.5001,0)  ;will return ''2''
  
 
== See also ==
 
== See also ==
 
+
* [[$int]]
[[$int]], [[$floor]] and [[$ceil]].
+
* [[$floor]]  
 +
* [[$ceil]]
  
 
[[Category:Text and Number Identifiers]]
 
[[Category:Text and Number Identifiers]]

Latest revision as of 10:07, 2 July 2007

Returns the floating number you specify rounded to the specified number of decimals.

$round(N,D)
  • N is the number you want to round.
  • D is the number of decimals you want.

Examples

The following will echo pi with 3 decimals:

 $round($pi,3)  ;will return 3.142
 $round(1.5001,0)  ;will return 2

See also