insert thousands separators

Gerhard Häring gh at
Mon Jun 16 16:00:42 CEST 2003

Nick Vargish wrote:
> ps. Looking at the library reference, it's not clear if there's an easy
> way to extract the fractional portion of a float without hitting the
> Standard Floating Point Problem:
>>>>v = 2312.3123123
>>>>v1 = int(v)
>>>>v2 = v - v1
> 0.31231230000003052

If you need that, then a float is probably not the right data type. 
There are several implementations of arbitrary precision numbers out there.

Some more fun with floats:

 >>> v - v1
 >>> s = str(v)
 >>> s
 >>> s[s.find("."):]
 >>> float(s[s.find("."):])

So if you only want to print the fractional value, str() will do fine. 
But str() won't make floats capable of representing arbitrary numbers, 
either ;-)

-- Gerhard

More information about the Python-list mailing list