Get Decimal/Floating Values On Current Frames Divided by FPS?
-
Hi,
Is it possible to get decimal/floating values when current frames is divided by FPS?
For instance, on a current frame of 12. FPS of 24.
Currently, it results to 0. I want it to be 0.5.Here is the working code:
import c4d fps= doc.GetFps() base_time = doc.GetTime() frame = base_time.GetFrame(fps) time_ratio = frame/fps print time_ratio
Thank you for looking at my problem
-
You might have to cast them to float before division. This is a known problem in Python 2.
You could simply do atime_ratio = frame/(fps * 1.0)
Alternatively, you could simply use- wrong, since this works only from 2.2 and up, not 2.17.from __future__ import division
but since we are in C4d environment, that might or might not work. -
hi,
that's the "problem" with python you have to be careful with your type.
Here, you are dividing anint
by anotherint
so the result will be aint
. (and a int of 0.4 is 0)If you type instead
frame/float(fps)
python will create a new float variable for fps.
now you are dividing anint
by afloat
so python return the result as afloat
.Cheers,
Manuel -
Thank you all. Works as expected.
-
-
@m_magalhaes said in Get Decimal/Floating Values On Current Frames Divided by FPS?:
If you type instead
frame/float(fps)
python will create a new float variable for fps.Although not likely in this case, casting the number may result in a TypeError if the number is a complex number.
-
@mp5gosu thanks for the addition.
Cheers,
Manuel