Hi Peter - there is some rounding problem with the PyFloat_FromDouble approach (if you compile with that and run the unit tests, you'll see a number of them fail). The temp string is a workaround for now.
Thanks for the note though - if you have time to find an approach that lets tests pass and avoids the temp, I'd be happy to check it in ;) Brian Lloyd [EMAIL PROTECTED] V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -----Original Message----- > From: Peter Schwalm [mailto:[EMAIL PROTECTED] > Sent: Saturday, February 05, 2005 7:58 PM > To: Brian Lloyd; [email protected] > Subject: Conversion of single precision floating point to python floats > > > Hi Brian, > > I recently had a problem retrieving a float value from a dotNet > function. I > had a conversion error which was caused by the local setting of > the decimal > separator (a comma here in germany). > > I figured out that you have already corrected this problem in > cvs. Before I > found these correction I have tried the following version, which I would > prefer because it does not use an intermediate string for the conversion. > > I don't know if you use this intermediate string accidentally - > possibly for > the sake of rounding that happens during conversion to a string? > > Anyway I would like to communicate my solution (your last cvs version > commented out): > > namespace Python.Runtime { > ... > internal class Converter { > ... > internal static IntPtr ToPython(Object value, Type type) { > ... > > case TypeCode.Single: > // string ss = ((float)value).ToString(nfi); > // IntPtr ps = Runtime.PyString_FromString(ss); > // IntPtr op = Runtime.PyFloat_FromString(ps, IntPtr.Zero); > // Runtime.Decref(ps); > // return op; > return Runtime.PyFloat_FromDouble((double) ((float)value)); > > Greetings > Peter Schwalm > > _________________________________________________ Python.NET mailing list - [email protected] http://mail.python.org/mailman/listinfo/pythondotnet
