Difference between revisions of "$int"
From Scriptwiki
m (Added example to return remainder) |
m (Added examples of negative numbers fixed a typo.) |
||
(2 intermediate revisions by 2 users 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 == | ||
− | $int([[$pi]]) | + | $int([[$pi]]) ;will return ''3'' |
− | $int(9312412.3213) | + | $int(9312412.3213) ;will return ''9312412'' |
[[var]] %i = 2.5 | [[var]] %i = 2.5 | ||
− | [[$calc]](%i - | + | [[$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]] |
+ | * [[$floor]] | ||
[[Category:Text and Number Identifiers]] | [[Category:Text and Number Identifiers]] |
Latest revision as of 09: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.