Badge time.png   The Paragon Wiki Archive documents the state of City of Heroes/Villains as it existed on December 1, 2012.

Difference between revisions of "Talk:Common Invention Recipes"

From Paragon Wiki Archive
Jump to: navigation, search
(Note to self)
 
(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)