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.