Remove integer from float number

John Machin sjmachin at lexicon.net
Thu Mar 23 20:53:01 CET 2006


On 24/03/2006 6:44 AM, Larry Bates wrote:
> Derek Basch wrote:
> 
>>How can I return:
>>
>>".666"
>>
>>from float:
>>
>>"0.666"
>>
>>This is what I have so far:
>>
>>
>>>>>"%.6f" % x
>>
>>Thanks Everyone,
>>Derek Basch
>>
> 
> 
> This works but I'm not entirely sure I know what you are
> trying to accomplish.
> 
> ("%.3f" % x)[1:]
> 

 >>> x = 12345.666; ("%.3f" % x)[1:]
'2345.666'
 >>>

I'm sure of neither what the OP is trying to accomplish nor what Larry's 
definition of "works" is :-)

Perhaps the condition abs(x) < 1.0 is implied ...



More information about the Python-list mailing list