 # 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).
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

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

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