$int: Difference between revisions

From Scriptwiki
Jump to navigation Jump to search
m fixed commenting
m Added examples of negative numbers fixed a typo.
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:


* ''N'' is the number with decimals you want to handle.
* ''N'' is the number with decimals you want to handle.
== Note ==
The difference between $int and [[$floor]] is only visible with negative numbers. For example:
$floor(5.6)  ;returns 5
$int(5.6)    ;returns 5
$floor(-5.6) ;returns -6
$int(-5.6)  ;returns -5


== Examples ==
== Examples ==
Line 11: Line 19:


  [[var]] %i = 2.5
  [[var]] %i = 2.5
  [[$calc]](%i - %int(%i))  ;will return ''0.5''
  [[$calc]](%i - $int(%i))  ;will return ''0.5''
$calc(%i % 1)  ;will also return ''0.5''
The above example shows how to return the remainder from a decimal number.
The above example shows how to return the remainder from a decimal number.
== See also ==
== See also ==
 
* [[$round]]
[[$round]], [[$ceil]] and [[$floor]].
* [[$ceil]]  
* [[$floor]]


[[Category:Text and Number Identifiers]]
[[Category:Text and Number Identifiers]]

Latest revision as of 08:32, 12 June 2012

Returns the specified integer number without rounding.

$int(N)
  • N is the number with decimals you want to handle.

Note

The difference between $int and $floor is only visible with negative numbers. For example:

$floor(5.6)  ;returns 5
$int(5.6)    ;returns 5
$floor(-5.6) ;returns -6
$int(-5.6)   ;returns -5

Examples

$int($pi)  ;will return 3
$int(9312412.3213)  ;will return 9312412
var %i = 2.5
$calc(%i - $int(%i))  ;will return 0.5
$calc(%i % 1)  ;will also return 0.5

The above example shows how to return the remainder from a decimal number.

See also