Skip to content

Commit 0533ae6

Browse files
Maxwell Careytonycoz
Maxwell Carey
authored andcommitted
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.
1 parent 9d293dd commit 0533ae6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pod/perlfunc.pod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7745,9 +7745,8 @@ For example:
77457745
printf '<%e>', 10; # prints "<1.000000e+01>"
77467746
printf '<%.1e>', 10; # prints "<1.0e+01>"
77477747

7748-
For "g" and "G", this specifies the maximum number of digits to show,
7749-
including those prior to the decimal point and those after it; for
7750-
example:
7748+
For "g" and "G", this specifies the maximum number of significant digits to
7749+
show; for example:
77517750

77527751
# These examples are subject to system-specific variation.
77537752
printf '<%g>', 1; # prints "<1>"
@@ -7757,6 +7756,9 @@ example:
77577756
printf '<%.2g>', 100.01; # prints "<1e+02>"
77587757
printf '<%.5g>', 100.01; # prints "<100.01>"
77597758
printf '<%.4g>', 100.01; # prints "<100>"
7759+
printf '<%.1g>', 0.0111; # prints "<0.01>"
7760+
printf '<%.2g>', 0.0111; # prints "<0.011>"
7761+
printf '<%.3g>', 0.0111; # prints "<0.0111>"
77607762

77617763
For integer conversions, specifying a precision implies that the
77627764
output of the number itself should be zero-padded to this width,

0 commit comments

Comments
 (0)