summaryrefslogtreecommitdiff
path: root/pod/perlfunc.pod
diff options
context:
space:
mode:
authorMaxwell Carey <maxwellhaydn@gmail.com>2016-05-09 15:33:41 -0600
committerTony Cook <tony@develop-help.com>2016-05-16 10:48:33 +1000
commit0533ae6f60432c9f45178df2a58a9b469f4e3464 (patch)
tree28cca2a731416d59321230b3261fd9f90c4f59e7 /pod/perlfunc.pod
parent9d293ddbfa9b2d5f12e8b7a40b44c1466fc9f148 (diff)
downloadperl-0533ae6f60432c9f45178df2a58a9b469f4e3464.tar.gz
Clarify description of sprintf "%.1g"
sprintf "%.1g" sets the number of *significant* digits, not the maximum number of digits to show. Added examples for values less than 1.
Diffstat (limited to 'pod/perlfunc.pod')
-rw-r--r--pod/perlfunc.pod8
1 files changed, 5 insertions, 3 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index e9c7038a9c..5c778f1b2f 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -7745,9 +7745,8 @@ For example:
printf '<%e>', 10; # prints "<1.000000e+01>"
printf '<%.1e>', 10; # prints "<1.0e+01>"
-For "g" and "G", this specifies the maximum number of digits to show,
-including those prior to the decimal point and those after it; for
-example:
+For "g" and "G", this specifies the maximum number of significant digits to
+show; for example:
# These examples are subject to system-specific variation.
printf '<%g>', 1; # prints "<1>"
@@ -7757,6 +7756,9 @@ example:
printf '<%.2g>', 100.01; # prints "<1e+02>"
printf '<%.5g>', 100.01; # prints "<100.01>"
printf '<%.4g>', 100.01; # prints "<100>"
+ printf '<%.1g>', 0.0111; # prints "<0.01>"
+ printf '<%.2g>', 0.0111; # prints "<0.011>"
+ printf '<%.3g>', 0.0111; # prints "<0.0111>"
For integer conversions, specifying a precision implies that the
output of the number itself should be zero-padded to this width,