How To Split A Number Into Integer And Decimal Parts In Python

Split a number into integer and decimal parts in Python

To split a number into integer and decimal parts in Python, you can use the divmod() function, the modf() function, the arithmetic operators and the int() function. Follow the article to understand better.

Split a number into integer and decimal parts in Python

Use the divmod() function

You can use the divmod() function to represent a number as integers and decimals.


divmod(x, y)


  • x: the dividend.
  • y: the divisor.


  • Returns a tuple(q,r) where q is the quotient and r is the remainder.
  • x,y are integers the return value will be (quotient, balance).
  • x or y is a float, the return value is (quotient, balance).


myNumber1 = 4.5
iNumber, fNumber = divmod(myNumber1, 1)
print('Integer parts', iNumber)
print('Decimal part', fNumber)


Integer parts 4.0
Decimal part 0.5

Use the modf() function 


math.modf( x )


  •  x: Numeric expression.


  • Import math module.
  • Initialize two numbers that can be integers, float.
  • Use the modf() function to represent division as integers and decimals.
import math

myNumber = 2.30

# Use the modf() function to divide numbers into decimal and integer parts
separatedNum = math.modf(myNumber)

print('Decimal part', separatedNum[0])
print('Integer part', separatedNum[1])


(0.2999999999999998, 2.0)
Decimal parts 0.2999999999999998
Integer part 2.0

Use the arithmetic operator

You can use arithmetic operators in conjunction with the int() function to represent numbers as integers and decimals.

The ‘%’ operator for division with remainder.

The ‘//’ operator operand division where the result is the quotient and the digits after the decimal point are removed.


# Value is an integer
myNumber = 3
result1 = (int(myNumber // 1), myNumber % 1)
print('Result1: ', result1)

# Value is a float
myNumber2 = 3.5
result2 = (int(myNumber2 // 1), myNumber2 % 1)
print('Result2: ', result2)


Result1 (3, 0)
Result2 (3, 0.5)

Use the int() function


  • Initialize a variable containing an integer or float value.
  • Use the int() function to represent a number as an integer and decimal.
# Value is a float
myNumber1 = 1.9

# Use the int() function
intpart1, decimalpart1 = int(myNumber1), myNumber1 - int(myNumber1)
print('Integer parts', intpart1)
print('Decimal part', decimalpart1)

# Value is an integer
myNumber2 = 1

# Use the int() function
intpart2, decimalpart2 = int(myNumber2), myNumber2 - int(myNumber2)
print('Integer parts', intpart2)
print('Decimal part', decimalpart2)
Integer parts 1
Decimal part 0.8999999999999999
Integer parts 1
Decimal part 0


Here are the solutions that can help you split a number into integer and decimal parts in Python. If you have any questions about this article, leave a comment below. I will answer your questions. Thank you for reading!

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *