@@ -17,6 +17,28 @@ def ordinal(value):
1717 anything `int()` will turn into an integer. Anything other value will have nothing
1818 done to it.
1919
20+ Examples:
21+ ```pycon
22+ >>> ordinal(1)
23+ '1st'
24+ >>> ordinal(1002)
25+ '1002nd'
26+ >>> ordinal(103)
27+ '103rd'
28+ >>> ordinal(4)
29+ '4th'
30+ >>> ordinal(12)
31+ '12th'
32+ >>> ordinal(101)
33+ '101st'
34+ >>> ordinal(111)
35+ '111th'
36+ >>> ordinal("something else")
37+ 'something else'
38+ >>> ordinal(None) is None
39+ True
40+
41+ ```
2042 Args:
2143 value (int, str, float): Integer to convert.
2244
@@ -50,6 +72,24 @@ def intcomma(value, ndigits=None):
5072 For example, 3000 becomes "3,000" and 45000 becomes "45,000". To maintain some
5173 compatibility with Django's `intcomma`, this function also accepts floats.
5274
75+ Examples:
76+ ``pycon
77+ >>> intcomma(100)
78+ '100'
79+ >>> intcomma("1000")
80+ '1,000'
81+ >>> intcomma(1_000_000)
82+ '1,000,000'
83+ >>> intcomma(1_234_567.25)
84+ '1,234,567.25'
85+ >>> intcomma(1234.5454545, 2)
86+ '1,234.55'
87+ >>> intcomma(14308.40, 1)
88+ '14,308.4'
89+ >>> intcomma(None) is None
90+ True
91+
92+ ```
5393 Args:
5494 value (int, float, str): Integer or float to convert.
5595 ndigits (int, None): Digits of precision for rounding after the decimal point.
@@ -100,6 +140,22 @@ def intword(value, format="%.1f"):
100140 1200000 becomes "1.2 million" and "1_200_000_000" becomes "1.2 billion". Supports up
101141 to decillion (33 digits) and googol (100 digits).
102142
143+ Examples:
144+ ```pycon
145+ >>> intword("100")
146+ '100'
147+ >>> intword("1000000")
148+ '1.0 million'
149+ >>> intword(1_200_000_000)
150+ '1.2 billion'
151+ >>> intword(8100000000000000000000000000000000)
152+ '8.1 decillion'
153+ >>> intword(None) is None
154+ True
155+ >>> intword("1234000", "%0.3f")
156+ '1.234 million'
157+
158+ ```
103159 Args:
104160 value (int, float, str): Integer to convert.
105161 format (str): To change the number of decimal or general format of the number
@@ -130,6 +186,22 @@ def intword(value, format="%.1f"):
130186def apnumber (value ):
131187 """Converts an integer to Associated Press style.
132188
189+ Examples:
190+ ```pycon
191+ >>> apnumber(0)
192+ 'zero'
193+ >>> apnumber(5)
194+ 'five'
195+ >>> apnumber(10)
196+ '10'
197+ >>> apnumber("7")
198+ 'seven'
199+ >>> apnumber("foo")
200+ 'foo'
201+ >>> apnumber(None) is None
202+ True
203+
204+ ```
133205 Args:
134206 value (int, float, str): Integer to convert.
135207
@@ -182,6 +254,11 @@ def fractional(value):
182254 '1/3'
183255 >>> fractional(1)
184256 '1'
257+ >>> fractional("ten")
258+ 'ten'
259+ >>> fractional(None) is None
260+ True
261+
185262 ```
186263 Args:
187264 value (int, float, str): Integer to convert.
@@ -216,6 +293,19 @@ def scientific(value, precision=2):
216293 '3.00 x 10⁻¹'
217294 >>> scientific(int(500))
218295 '5.00 x 10²'
296+ >>> scientific(-1000)
297+ '1.00 x 10⁻³'
298+ >>> scientific(1000, 1)
299+ '1.0 x 10³'
300+ >>> scientific(1000, 3)
301+ '1.000 x 10³'
302+ >>> scientific("99")
303+ '9.90 x 10¹'
304+ >>> scientific("foo")
305+ 'foo'
306+ >>> scientific(None) is None
307+ True
308+
219309 ```
220310
221311 Args:
0 commit comments