LEFT | RIGHT |
1 -- 'f' code formatting, with explicit precision (>= 0). Output always | 1 -- 'f' code formatting, with explicit precision (>= 0). Output always |
2 -- has the given number of places after the point; zeros are added if | 2 -- has the given number of places after the point; zeros are added if |
3 -- necessary to make this true. | 3 -- necessary to make this true. |
4 | 4 |
5 -- zeros | 5 -- zeros |
6 %.0f 0 -> 0 | 6 %.0f 0 -> 0 |
7 %.1f 0 -> 0.0 | 7 %.1f 0 -> 0.0 |
8 %.2f 0 -> 0.00 | 8 %.2f 0 -> 0.00 |
9 %.3f 0 -> 0.000 | 9 %.3f 0 -> 0.000 |
10 %.50f 0 -> 0.00000000000000000000000000000000000000000000000000 | 10 %.50f 0 -> 0.00000000000000000000000000000000000000000000000000 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 %#.4g 20 -> 20.00 | 307 %#.4g 20 -> 20.00 |
308 | 308 |
309 %#.0g 234.56 -> 2.e+02 | 309 %#.0g 234.56 -> 2.e+02 |
310 %#.1g 234.56 -> 2.e+02 | 310 %#.1g 234.56 -> 2.e+02 |
311 %#.2g 234.56 -> 2.3e+02 | 311 %#.2g 234.56 -> 2.3e+02 |
312 %#.3g 234.56 -> 235. | 312 %#.3g 234.56 -> 235. |
313 %#.4g 234.56 -> 234.6 | 313 %#.4g 234.56 -> 234.6 |
314 %#.5g 234.56 -> 234.56 | 314 %#.5g 234.56 -> 234.56 |
315 %#.6g 234.56 -> 234.560 | 315 %#.6g 234.56 -> 234.560 |
316 | 316 |
317 -- repr formatting. Should always include a decimal point (and at | 317 -- for repr formatting see the separate test_short_repr test in |
318 -- least one digit after the point) or an exponent. Produces the shortest | 318 -- test_float.py. Not all platforms use short repr for floats. |
319 -- string that rounds correctly. | |
320 | |
321 %r 0 -> 0.0 | |
322 %r 1 -> 1.0 | |
323 | |
324 -- check short repr | |
325 %r 0.01 -> 0.01 | |
326 %r 0.02 -> 0.02 | |
327 %r 0.03 -> 0.03 | |
328 %r 0.04 -> 0.04 | |
329 %r 0.05 -> 0.05 | |
330 %r 1.23456789 -> 1.23456789 | |
331 %r 10 -> 10.0 | |
332 %r 100 -> 100.0 | |
333 | |
334 -- values >= 1e16 get an exponent | |
335 %r 1e15 -> 1000000000000000.0 | |
336 %r 0.999999999999e16 -> 9999999999990000.0 | |
337 %r 1e16 -> 1e+16 | |
338 %r 1.000000000001e16 -> 1.000000000001e+16 | |
339 %r 1e17 -> 1e+17 | |
340 | |
341 -- as do values < 1e-4 | |
342 %r 1e-3 -> 0.001 | |
343 %r 1.001e-4 -> 0.0001001 | |
344 %r 1.000000000001e-4 -> 0.0001000000000001 | |
345 %r 1e-4 -> 0.0001 | |
346 %r 0.999999999999e-4 -> 9.99999999999e-05 | |
347 %r 0.999e-4 -> 9.99e-05 | |
348 %r 1e-5 -> 1e-05 | |
349 | |
350 -- some values that are designed to fail if the FPU rounding | |
351 -- precision is 64-bits. | |
352 %r 8.72293771110361e+25 -> 8.72293771110361e+25 | |
353 %r 7.47005307342313e+26 -> 7.47005307342313e+26 | |
354 %r 2.86438000439698e+28 -> 2.86438000439698e+28 | |
355 %r 8.89142905246179e+28 -> 8.89142905246179e+28 | |
356 %r 3.08578087079232e+35 -> 3.08578087079232e+35 | |
357 | |
358 | 319 |
359 -- str formatting. Result always includes decimal point and at | 320 -- str formatting. Result always includes decimal point and at |
360 -- least one digit after the point, or an exponent. | 321 -- least one digit after the point, or an exponent. |
361 %s 0 -> 0.0 | 322 %s 0 -> 0.0 |
362 %s 1 -> 1.0 | 323 %s 1 -> 1.0 |
363 | 324 |
364 %s 0.01 -> 0.01 | 325 %s 0.01 -> 0.01 |
365 %s 0.02 -> 0.02 | 326 %s 0.02 -> 0.02 |
366 %s 0.03 -> 0.03 | 327 %s 0.03 -> 0.03 |
367 %s 0.04 -> 0.04 | 328 %s 0.04 -> 0.04 |
(...skipping 16 matching lines...) Expand all Loading... |
384 -- as do values < 1e-4 | 345 -- as do values < 1e-4 |
385 %s 1e-3 -> 0.001 | 346 %s 1e-3 -> 0.001 |
386 %s 1.001e-4 -> 0.0001001 | 347 %s 1.001e-4 -> 0.0001001 |
387 %s 1.000000000001e-4 -> 0.0001 | 348 %s 1.000000000001e-4 -> 0.0001 |
388 %s 1.00000000001e-4 -> 0.000100000000001 | 349 %s 1.00000000001e-4 -> 0.000100000000001 |
389 %s 1.0000000001e-4 -> 0.00010000000001 | 350 %s 1.0000000001e-4 -> 0.00010000000001 |
390 %s 1e-4 -> 0.0001 | 351 %s 1e-4 -> 0.0001 |
391 %s 0.999999999999e-4 -> 9.99999999999e-05 | 352 %s 0.999999999999e-4 -> 9.99999999999e-05 |
392 %s 0.999e-4 -> 9.99e-05 | 353 %s 0.999e-4 -> 9.99e-05 |
393 %s 1e-5 -> 1e-05 | 354 %s 1e-5 -> 1e-05 |
LEFT | RIGHT |