getting the fractional part of a real?
Roy Smith
roy at panix.com
Sat Aug 15 16:01:25 EDT 2009
In article <4a8704ca$0$2292$91cee783 at newsreader02.highway.telekom.at>,
Gregor Lingl <gregor.lingl at aon.at> wrote:
> Christian Heimes schrieb:
> > Roy Smith schrieb:
> >> What's the best way to get the fractional part of a real? The two
> >> ways I can see are r % 1 and r = int(r), but both seem a bit hokey.
> >> Is there something more straight-forward that I'm missing, like
> >> fraction(r)?
> >
> >>>> import math
> >>>> math.modf(1.5)
> > (0.5, 1.0)
> >
> > Christian
>
> Or without the need to import something:
>
> >>> divmod(1.5, 1)
> (1.0, 0.5)
> >>>
>
> Gregor
Thanks. I knew I had to be missing something obvious.
Regarding Mark Dickinson's question about what I want for negative reals,
for the application I have in mind, r is guaranteed to be positive.
More information about the Python-list
mailing list