1 -- 'f' code formatting, with explicit precision (>= 0). Output always
2 -- has the given number of places after the point; zeros are added if
3 -- necessary to make this true.
10 %.50f 0 -> 0.00000000000000000000000000000000000000000000000000
12 -- precision 0; result should never include a .
24 %.0f 1e49 -> 9999999999999999464902769475481793196872414789632
25 %.0f 9.9999999999999987e+49 -> 99999999999999986860582406952576489172979654066176
26 %.0f 1e50 -> 100000000000000007629769841091887003294964970946560
39 %.1f 1000.03 -> 1000.0
40 %.1f 1234.5678 -> 1234.6
41 %.1f 1234.7499 -> 1234.7
42 %.1f 1234.75 -> 1234.8
52 %.2f 1234500 -> 1234500.00
53 %.2f 1234560 -> 1234560.00
54 %.2f 1234567 -> 1234567.00
55 %.2f 1234567.8 -> 1234567.80
56 %.2f 1234567.89 -> 1234567.89
57 %.2f 1234567.891 -> 1234567.89
58 %.2f 1234567.8912 -> 1234567.89
60 -- alternate form always includes a decimal point. This only
61 -- makes a difference when the precision is 0.
67 %#.0f 1234.56 -> 1235.
71 -- if precision is omitted it defaults to 6
73 %f 1230000 -> 1230000.000000
74 %f 1234567 -> 1234567.000000
75 %f 123.4567 -> 123.456700
76 %f 1.23456789 -> 1.234568
77 %f 0.00012 -> 0.000120
78 %f 0.000123 -> 0.000123
79 %f 0.00012345 -> 0.000123
80 %f 0.000001 -> 0.000001
81 %f 0.0000005001 -> 0.000001
82 %f 0.0000004999 -> 0.000000
84 -- nans and infinities
92 -- 'e' code formatting with explicit precision (>= 0). Output should
93 -- always have exactly the number of places after the point that were
100 %.10e 0 -> 0.0000000000e+00
101 %.50e 0 -> 0.00000000000000000000000000000000000000000000000000e+00
103 -- precision 0. no decimal point in the output
114 %.0e 123.456 -> 1e+02
115 %.0e 0.000123456 -> 1e-04
116 %.0e 123456000 -> 1e+08
121 %.0e 2.4999999 -> 2e+00
123 %.0e 2.5000001 -> 3e+00
124 %.0e 3.499999999999 -> 3e+00
138 %.1e 0.0001 -> 1.0e-04
139 %.1e 0.001 -> 1.0e-03
147 %.1e 123.4 -> 1.2e+02
150 %.2e 0.00013 -> 1.30e-04
151 %.2e 0.000135 -> 1.35e-04
152 %.2e 0.0001357 -> 1.36e-04
153 %.2e 0.0001 -> 1.00e-04
154 %.2e 0.001 -> 1.00e-03
155 %.2e 0.01 -> 1.00e-02
160 %.2e 1000 -> 1.00e+03
161 %.2e 1500 -> 1.50e+03
162 %.2e 1590 -> 1.59e+03
163 %.2e 1598 -> 1.60e+03
164 %.2e 1598.7 -> 1.60e+03
165 %.2e 1598.76 -> 1.60e+03
166 %.2e 9999 -> 1.00e+04
168 -- omitted precision defaults to 6
170 %e 165 -> 1.650000e+02
171 %e 1234567 -> 1.234567e+06
172 %e 12345678 -> 1.234568e+07
173 %e 1.1 -> 1.100000e+00
175 -- alternate form always contains a decimal point. This only makes
176 -- a difference when precision is 0.
183 %#.0e 0.012 -> 1.e-02
188 %#.0e 123.456 -> 1.e+02
189 %#.0e 0.000123456 -> 1.e-04
190 %#.0e 123456000 -> 1.e+08
195 %#.0e 2.4999999 -> 2.e+00
197 %#.0e 2.5000001 -> 3.e+00
198 %#.0e 3.499999999999 -> 3.e+00
205 %#.0e 9.4999 -> 9.e+00
208 %#.0e 14.999 -> 1.e+01
210 %#.1e 123.4 -> 1.2e+02
211 %#.2e 0.0001357 -> 1.36e-04
213 -- nans and infinities
221 -- 'g' code formatting.
233 -- precision 0 doesn't make a lot of sense for the 'g' code (what does
234 -- it mean to have no significant digits?); in practice, it's interpreted
235 -- as identical to precision 1
252 %.0g 0.00012 -> 0.0001
253 %.0g 0.000012 -> 1e-05
254 %.0g 0.0000012 -> 1e-06
256 -- precision 1 identical to precision 0
273 %.1g 0.00012 -> 0.0001
274 %.1g 0.000012 -> 1e-05
275 %.1g 0.0000012 -> 1e-06
294 %.2g 0.00123 -> 0.0012
295 %.2g 0.000123 -> 0.00012
296 %.2g 0.0000123 -> 1.2e-05
298 -- alternate g formatting: always include decimal point and
299 -- exactly <precision> significant digits.
311 %#.10g 0.2 -> 0.2000000000
325 %#.0g 234.56 -> 2.e+02
326 %#.1g 234.56 -> 2.e+02
327 %#.2g 234.56 -> 2.3e+02
329 %#.4g 234.56 -> 234.6
330 %#.5g 234.56 -> 234.56
331 %#.6g 234.56 -> 234.560
333 -- nans and infinities
341 -- for repr formatting see the separate test_short_repr test in
342 -- test_float.py. Not all platforms use short repr for floats.
344 -- str formatting. Result always includes decimal point and at
345 -- least one digit after the point, or an exponent.
355 -- str truncates to 12 significant digits
356 %s 1.234123412341 -> 1.23412341234
357 %s 1.23412341234 -> 1.23412341234
358 %s 1.2341234123 -> 1.2341234123
360 -- values >= 1e11 get an exponent
363 %s 1e10 -> 10000000000.0
364 %s 9.999e10 -> 99990000000.0
365 %s 99999999999 -> 99999999999.0
366 %s 99999999999.9 -> 99999999999.9
367 %s 99999999999.99 -> 1e+11
371 -- as do values < 1e-4
373 %s 1.001e-4 -> 0.0001001
374 %s 1.000000000001e-4 -> 0.0001
375 %s 1.00000000001e-4 -> 0.000100000000001
376 %s 1.0000000001e-4 -> 0.00010000000001
378 %s 0.999999999999e-4 -> 9.99999999999e-05
379 %s 0.999e-4 -> 9.99e-05