Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Convert Float to Integer

Convert a floating-point number to an integer by truncating the fractional part.

Python practice15 minVariables & Data TypesIntermediateLast updated January 2, 2026

Problem statement

Given a single floating-point number, return its integer conversion using Python's default behavior: drop the fractional part (truncate toward zero). Do not round — simply convert to int. For example, 3.9 becomes 3, -2.7 becomes -2, and 0.0 becomes 0.

Task

Write a function that converts a float to an integer using Python's truncation behavior (toward zero).

Examples

Positive float

Input

convert_float_to_int(3.9)

Output

3

The fractional part .9 is dropped, producing 3.

Input format

A single floating-point number is passed as the only argument to the function convert_float_to_int.

Output format

Return an integer that is the result of converting the input float to int.

Constraints

- Use Python's int conversion semantics (truncate toward zero). - Input will be a finite float (no need to handle NaN or infinity for this exercise).

Samples

Sample 1

Input

convert_float_to_int(-2.7)

Output

-2

Negative floats truncate toward zero, so -2.7 -> -2.