On 3/24/15 6:39 PM, Jason Swails wrote:


On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille <em...@fenx.com
<mailto:em...@fenx.com>> wrote:

    On 3/23/2015 5:52 AM, Steven D'Aprano wrote:

        Are there any other, possibly better, ways to calculate the
        fractional part
        of a number?


    float (("%6.3f" % x)[-4:])


​In general you lose a lot of precision this way...​

I suggest modf in the math library:

math.modf(x)
Return the fractional and integer parts of x. Both results carry the sign of x and are floats.



--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to