splitting a number into the integer and decimal parts Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of splitting a number into the integer and decimal parts without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Is there a pythonic way of splitting a number such as 1234.5678 into two parts (1234, 0.5678) i.e. the integer part and the decimal part?

Answer

Use math.modf:

import math
x = 1234.5678
math.modf(x) # (0.5678000000000338, 1234.0)
We are here to answer your question about splitting a number into the integer and decimal parts - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji