Talk:Common Invention Recipes: Difference between revisions

From Unofficial Homecoming Wiki
Jump to navigation Jump to search
imported>Lin Chiao Feng
(Note to self)
 
imported>Lin Chiao Feng
(Replacing page with '(Code copied to sources and deleted from here.) --~~~~')
Line 1: Line 1:
==Python Stuff==
(Code copied to sources and deleted from here.) --[[User:Lin Chiao Feng|Lin Chiao Feng]] 07:08, 18 April 2007 (PDT)
Note to self:
<pre>def commify(amount):
    amount = str(amount).strip()
    try:
        whole, fract = amount.split('.', 1)
        fract = '.' + fract
    except ValueError:
        whole = amount
        fract = ''
    firstcomma = len(whole)%3 or 3  # set to 3 if would make a leading comma
    first, rest = whole[:firstcomma], whole[firstcomma:]
    segments = [first] + [rest[i:i+3] for i in range(0, len(rest), 3)]
    return ",".join(segments) + fract
</pre>
Based on code from http://pleac.sourceforge.net/pleac_python/numbers.html. (Added code to handle decimals.) --[[User:Lin Chiao Feng|Lin Chiao Feng]] 06:18, 18 April 2007 (PDT)

Revision as of 14:08, 18 April 2007

(Code copied to sources and deleted from here.) --Lin Chiao Feng 07:08, 18 April 2007 (PDT)