BaldDude
BaldDude

Reputation: 1161

Python conversion from c_double to float

I am new to Python. I would like to know what would be the best way to convert a c_double (from ctypes) to a float. My code is working, but I would like to know if there is a pythonic way to do it. What I currently do is:

FloatValue = float( str(d_Val)[9:( len( str(d_Val) ) )-1] )

Where d_Val is c_double(-10.0), and I want to keep -10.0 Working with Python 2.7 under windows.

Upvotes: 7

Views: 10192

Answers (1)

tom
tom

Reputation: 19163

Use the value property on a c_double.

>>> ctypes.c_double(-10.0).value
-10.0

Upvotes: 15

Related Questions