Getting fractional part from a float without using string operations

MRAB google at mrabarnett.plus.com
Wed Nov 19 14:46:50 CET 2008


On Nov 19, 1:44 pm, John Machin <sjmac... at lexicon.net> wrote:
> On Nov 20, 12:35 am, srinivasan srinivas <sri_anna... at yahoo.co.in>
> wrote:
> <null>
>
> | >>> import math
> | >>> num = 123.4567
> | >>> math.modf(num)
> | (0.45669999999999789, 123.0)

def frac(n):
    return n - int(n)



More information about the Python-list mailing list