So if i run
a = b / c
and get the result 1.2234
How do i separate it so that I have
a = 1 b = 0.2234
So if i run
a = b / c
and get the result 1.2234
How do i separate it so that I have
a = 1 b = 0.2234
Try:
a, b = int(a), a - int(a)
Bonus: works for negative numbers as well. -1.7
is split into -1
and -0.7
instead of -2
and 0.3
.
EDIT If a
is guaranteed to be non-negative, then gnibbler's solution is the way to go.
EDIT 2 IMHO, Odomontois' solution beats both mine and gnibbler's.
>>> from math import modf
>>> b,a = modf(1.2234)
>>> print ('a = %f and b = %f'%(a,b))
a = 1.000000 and b = 0.223400
>>> b,a = modf(-1.2234)
>>> print ('a = %f and b = %f'%(a,b))
a = -1.000000 and b = -0.223400