Remove integer from float number
Grant Edwards
grante at visi.com
Thu Mar 23 17:26:49 EST 2006
On 2006-03-23, Michael Yanowitz <m.yanowitz at kearfott.com> wrote:
>> With that terse description and the subject line I would interpret the
>> OP like so:
>>
>>>>> print re.sub(".*\.",".","0.666")
>> .666
>>>>> print re.sub(".*\.",".","123.666")
>> .666
>
> Or if you're allergic to regular expressions:
>
>>>> print "." + "0.666".split(".")[-1]
> .666
>>>> print "." + "123.666".split(".")[-1]
> .666
>>>>
> how about this solution:
> def printDecimal(number):
> if (number < 0):
> print number - int(number)
> else:
> print int(number) - number
Well, for one thing it doesn't work:
>>> def printDecimal(number):
... if (number < 0):
... print number - int(number)
... else:
... print int(number) - number
...
>>> printDecimal(0.666)
-0.666
>>> printDecimal(-0.666)
-0.666
>>>
Secondly, it was top-posted. ;)
--
Grant Edwards grante Yow! I appoint you
at ambassador to Fantasy
visi.com Island!!!
More information about the Python-list
mailing list