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 -- 'e' code formatting with explicit precision (>= 0). Output should
85 -- always have exactly the number of places after the point that were
92 %.10e 0 -> 0.0000000000e+00
93 %.50e 0 -> 0.00000000000000000000000000000000000000000000000000e+00
95 -- precision 0. no decimal point in the output
106 %.0e 123.456 -> 1e+02
107 %.0e 0.000123456 -> 1e-04
108 %.0e 123456000 -> 1e+08
113 %.0e 2.4999999 -> 2e+00
115 %.0e 2.5000001 -> 3e+00
116 %.0e 3.499999999999 -> 3e+00
130 %.1e 0.0001 -> 1.0e-04
131 %.1e 0.001 -> 1.0e-03
139 %.1e 123.4 -> 1.2e+02
142 %.2e 0.00013 -> 1.30e-04
143 %.2e 0.000135 -> 1.35e-04
144 %.2e 0.0001357 -> 1.36e-04
145 %.2e 0.0001 -> 1.00e-04
146 %.2e 0.001 -> 1.00e-03
147 %.2e 0.01 -> 1.00e-02
152 %.2e 1000 -> 1.00e+03
153 %.2e 1500 -> 1.50e+03
154 %.2e 1590 -> 1.59e+03
155 %.2e 1598 -> 1.60e+03
156 %.2e 1598.7 -> 1.60e+03
157 %.2e 1598.76 -> 1.60e+03
158 %.2e 9999 -> 1.00e+04
160 -- omitted precision defaults to 6
162 %e 165 -> 1.650000e+02
163 %e 1234567 -> 1.234567e+06
164 %e 12345678 -> 1.234568e+07
165 %e 1.1 -> 1.100000e+00
167 -- alternate form always contains a decimal point. This only makes
168 -- a difference when precision is 0.
175 %#.0e 0.012 -> 1.e-02
180 %#.0e 123.456 -> 1.e+02
181 %#.0e 0.000123456 -> 1.e-04
182 %#.0e 123456000 -> 1.e+08
187 %#.0e 2.4999999 -> 2.e+00
189 %#.0e 2.5000001 -> 3.e+00
190 %#.0e 3.499999999999 -> 3.e+00
197 %#.0e 9.4999 -> 9.e+00
200 %#.0e 14.999 -> 1.e+01
202 %#.1e 123.4 -> 1.2e+02
203 %#.2e 0.0001357 -> 1.36e-04
205 -- 'g' code formatting.
217 -- precision 0 doesn't make a lot of sense for the 'g' code (what does
218 -- it mean to have no significant digits?); in practice, it's interpreted
219 -- as identical to precision 1
236 %.0g 0.00012 -> 0.0001
237 %.0g 0.000012 -> 1e-05
238 %.0g 0.0000012 -> 1e-06
240 -- precision 1 identical to precision 0
257 %.1g 0.00012 -> 0.0001
258 %.1g 0.000012 -> 1e-05
259 %.1g 0.0000012 -> 1e-06
278 %.2g 0.00123 -> 0.0012
279 %.2g 0.000123 -> 0.00012
280 %.2g 0.0000123 -> 1.2e-05
282 -- alternate g formatting: always include decimal point and
283 -- exactly <precision> significant digits.
295 %#.10g 0.2 -> 0.2000000000
309 %#.0g 234.56 -> 2.e+02
310 %#.1g 234.56 -> 2.e+02
311 %#.2g 234.56 -> 2.3e+02
313 %#.4g 234.56 -> 234.6
314 %#.5g 234.56 -> 234.56
315 %#.6g 234.56 -> 234.560
317 -- for repr formatting see the separate test_short_repr test in
318 -- test_float.py. Not all platforms use short repr for floats.
320 -- str formatting. Result always includes decimal point and at
321 -- least one digit after the point, or an exponent.
331 -- str truncates to 12 significant digits
332 %s 1.234123412341 -> 1.23412341234
333 %s 1.23412341234 -> 1.23412341234
334 %s 1.2341234123 -> 1.2341234123
336 -- values >= 1e11 get an exponent
339 %s 1e10 -> 10000000000.0
340 %s 9.999e10 -> 99990000000.0
341 %s 99999999999 -> 99999999999.0
342 %s 99999999999.9 -> 99999999999.9
343 %s 99999999999.99 -> 1e+11
347 -- as do values < 1e-4
349 %s 1.001e-4 -> 0.0001001
350 %s 1.000000000001e-4 -> 0.0001
351 %s 1.00000000001e-4 -> 0.000100000000001
352 %s 1.0000000001e-4 -> 0.00010000000001
354 %s 0.999999999999e-4 -> 9.99999999999e-05
355 %s 0.999e-4 -> 9.99e-05