SOLVED 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 a

time_ratio = frame/(fps * 1.0)

Alternatively, you could simply use from __future__ import division but since we are in C4d environment, that might or might not work. - wrong, since this works only from 2.2 and up, not 2.17.

hi,

that's the "problem" with python you have to be careful with your type.
Here, you are dividing an int by another int so the result will be a int. (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 an int by a float so python return the result as a float.

Cheers,
Manuel

Thank you all. Works as expected.

hi,

just for your information in this page you can see the Mapping Operators to Functions table.
also this link
This inform you that in python 3, the default / will do a real div while if you want a floor div you will need to use //

Cheers,
Manuel

@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