aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorEli Zaretskii2017-01-28 10:30:17 +0200
committerEli Zaretskii2017-01-28 10:30:17 +0200
commitc331f393c120208983a4c9890cfd606635ef782a (patch)
treedfff4a2ff8ac6d96459560d79eda415f26c67259 /doc
parent9f52f67a967819916eedfe55f4ea92f659133dc5 (diff)
downloademacs-c331f393c120208983a4c9890cfd606635ef782a.tar.gz
emacs-c331f393c120208983a4c9890cfd606635ef782a.zip
Improve documentation of 'format' conversions
* src/editfns.c (Fformat): More accurate description of %g and effects of the various flags on it. More accurate description of integer conversions. * doc/lispref/strings.texi (Formatting Strings): More accurate description of %g and effects of the various flags on it. More accurate description of integer conversions. (Bug#25557)
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/strings.texi32
1 files changed, 20 insertions, 12 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index d343bcf5eff..d5980f62bd4 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -893,17 +893,18 @@ Functions}). Thus, strings are enclosed in @samp{"} characters, and
893@item %o 893@item %o
894@cindex integer to octal 894@cindex integer to octal
895Replace the specification with the base-eight representation of an 895Replace the specification with the base-eight representation of an
896integer. 896unsigned integer.
897 897
898@item %d 898@item %d
899Replace the specification with the base-ten representation of an 899Replace the specification with the base-ten representation of a signed
900integer. 900integer.
901 901
902@item %x 902@item %x
903@itemx %X 903@itemx %X
904@cindex integer to hexadecimal 904@cindex integer to hexadecimal
905Replace the specification with the base-sixteen representation of an 905Replace the specification with the base-sixteen representation of an
906integer. @samp{%x} uses lower case and @samp{%X} uses upper case. 906unsigned integer. @samp{%x} uses lower case and @samp{%X} uses upper
907case.
907 908
908@item %c 909@item %c
909Replace the specification with the character which is the value given. 910Replace the specification with the character which is the value given.
@@ -918,8 +919,9 @@ floating-point number.
918 919
919@item %g 920@item %g
920Replace the specification with notation for a floating-point number, 921Replace the specification with notation for a floating-point number,
921using either exponential notation or decimal-point notation, whichever 922using either exponential notation or decimal-point notation. The
922is shorter. 923exponential notation is used if the exponent would be less than -4 or
924greater than or equal to the precision (default: 6).
923 925
924@item %% 926@item %%
925Replace the specification with a single @samp{%}. This format 927Replace the specification with a single @samp{%}. This format
@@ -1000,9 +1002,11 @@ both flags are used, @samp{+} takes precedence.
1000 The flag @samp{#} specifies an alternate form which depends on 1002 The flag @samp{#} specifies an alternate form which depends on
1001the format in use. For @samp{%o}, it ensures that the result begins 1003the format in use. For @samp{%o}, it ensures that the result begins
1002with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result 1004with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result
1003with @samp{0x} or @samp{0X}. For @samp{%e}, @samp{%f}, and @samp{%g}, 1005with @samp{0x} or @samp{0X}. For @samp{%e} and @samp{%f}, the
1004the @samp{#} flag means include a decimal point even if the precision 1006@samp{#} flag means include a decimal point even if the precision is
1005is zero. 1007zero. For @samp{%g}, it always includes a decimal point, and also
1008forces any trailing zeros after the decimal point to be left in place
1009where they would otherwise be removed.
1006 1010
1007 The flag @samp{0} ensures that the padding consists of @samp{0} 1011 The flag @samp{0} ensures that the padding consists of @samp{0}
1008characters instead of spaces. This flag is ignored for non-numerical 1012characters instead of spaces. This flag is ignored for non-numerical
@@ -1033,10 +1037,14 @@ ignored.
1033 All the specification characters allow an optional @dfn{precision} 1037 All the specification characters allow an optional @dfn{precision}
1034before the character (after the width, if present). The precision is 1038before the character (after the width, if present). The precision is
1035a decimal-point @samp{.} followed by a digit-string. For the 1039a decimal-point @samp{.} followed by a digit-string. For the
1036floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the 1040floating-point specifications (@samp{%e} and @samp{%f}), the
1037precision specifies how many decimal places to show; if zero, the 1041precision specifies how many digits following the decimal point to
1038decimal-point itself is also omitted. For @samp{%s} and @samp{%S}, 1042show; if zero, the decimal-point itself is also omitted. For
1039the precision truncates the string to the given width, so @samp{%.3s} 1043@samp{%g}, the precision specifies how many significant digits to show
1044(significant digits are the first digit before the decimal point and
1045all the digits after it). If the precision of %g is zero or
1046unspecified, it is treated as 1. For @samp{%s} and @samp{%S}, the
1047precision truncates the string to the given width, so @samp{%.3s}
1040shows only the first three characters of the representation for 1048shows only the first three characters of the representation for
1041@var{object}. For other specification characters, the effect of 1049@var{object}. For other specification characters, the effect of
1042precision is what the local library functions of the @code{printf} 1050precision is what the local library functions of the @code{printf}