Logo

Programming-Idioms

Declare integer y and initialize it with the value of floating point number x . Ignore non-integer digits of x .
Make sure to truncate towards zero: a negative x must yield the closest greater integer (not lesser).
Implementation
Pascal

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Pascal implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
int y = (int)x;
y = x.to_i
y = trunc(x)
int y = cast(int)x;
y = truncate x
let y = x as i32;
int y = x.toInt()
y = int(x)
y := int(x)
my $y = int($x);
$y = (int)$x;
y = math.modf(x)
int y = (int)x;
let y = BigInt (x | 0)
int y = static_cast<int>(x);
int y = (int)x;
integer :: y
real  :: x
y=x
def y = x as int
Y : constant Integer := Integer (Float'Truncation (X));
(truncate x)