$int: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m Added examples of negative numbers fixed a typo. |
||
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 - | [[$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. | ||
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.