How to Remove a Decimal Point from a Number in Python

Python is a versatile high-level programming language used for numerous applications. One common task you might face while dealing with numerical data is to remove the decimal point from a number.

The process is straightforward and can be done by applying Python’s built-in functions. In this tutorial, we will elaborate on the steps necessary to remove a decimal point from a number in Python.

Step 1: Identifying a Decimal Number

Python treats decimal numbers also known as floating point numbers differently than it treats integers. The decimal point is the symbol that distinguishes floating point numbers from integers. Here is an example:

12.34

In the above case ‘12.34’ is a floating point number.

Step 2: Using the int() Function to Remove the Decimal Point

Python comes built-in with a function called int(). This function can be used to remove the decimal point from a number. It does so by truncating everything after the decimal point.

12

As seen above, the int() function removed everything after the dot, returning a clean integer value.

Step 3: Be Aware of Integers Resulting from Rounding Errors

A word of caution is warranted when attempting to delete decimal points by using the int() function. Rounding errors can occur as the decimal figures are not rounded, but simply truncated. If you want to manage such errors, consider using the round() function first, to convert the float to the nearest integer.

12 

Here, the round() function correctly rounded the float value before the int() function truncated the decimal point.

Full Code:

Conclusion

Removing the decimal point from a number is a common occurrence in Python when dealing with numerical data. Python’s built-in int() function makes the process straightforward by truncating all figures after the decimal point.

Be aware of potential rounding errors in certain situations. In such cases, the round() function is a good solution.