From 9e94a7e46770c6b7b90d91fff967d19a2fdca186 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Mon, 27 Jul 2009 18:55:27 -0400 Subject: [PATCH] .25 --> .24 since the original gives inconsistent results between python 3.0 and python 3.1 and I don't feel like figuring out why --- strings.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strings.html b/strings.html index 98c02d1..fa013ca 100755 --- a/strings.html +++ b/strings.html @@ -210,11 +210,11 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):

Format specifiers allow you to munge the replacement text in a variety of useful ways, like the printf() function in C. You can add zero- or space-padding, align strings, control decimal precision, and even convert numbers to hexadecimal. -

Within a replacement field, a colon (:) marks the start of the format specifier. The format specifier “.1” means “round to the nearest tenth” (i.e. display only one digit after the decimal point). The format specifier “f” means “fixed-point number” (as opposed to exponential notation or some other decimal representation). Thus, given a size of 698.25 and suffix of 'GB', the formatted string would be '698.3 GB', because 698.25 gets rounded to one decimal place, then the suffix is appended after the number. +

Within a replacement field, a colon (:) marks the start of the format specifier. The format specifier “.1” means “round to the nearest tenth” (i.e. display only one digit after the decimal point). The format specifier “f” means “fixed-point number” (as opposed to exponential notation or some other decimal representation). Thus, given a size of 698.24 and suffix of 'GB', the formatted string would be '698.2 GB', because 698.24 gets rounded to one decimal place, then the suffix is appended after the number.

->>> '{0:.1f} {1}'.format(698.25, 'GB')
-'698.3 GB'
+>>> '{0:.1f} {1}'.format(698.24, 'GB') +'698.2 GB'

For all the gory details on format specifiers, consult the Format Specification Mini-Language in the official Python documentation.