Commit 6b9c782f authored by Daniela Petruzalek's avatar Daniela Petruzalek Committed by Rob Pike

strconv: clarify "g" and "G" precision in the docs

Fix the wording in "strconv" and "fmt" to make explicit
that the "g" and "G" formats remove trailing zeroes.

Fixes #25082

Change-Id: I2e2ad0a98d2ea27a3a8a006a0563b366f7a3b71b
Reviewed-on: https://go-review.googlesource.com/127135Reviewed-by: default avatarRob Pike <r@golang.org>
parent b7d3f4c0
...@@ -97,10 +97,11 @@ ...@@ -97,10 +97,11 @@
For floating-point values, width sets the minimum width of the field and For floating-point values, width sets the minimum width of the field and
precision sets the number of places after the decimal, if appropriate, precision sets the number of places after the decimal, if appropriate,
except that for %g/%G precision sets the total number of significant except that for %g/%G precision sets the maximum number of significant
digits. For example, given 12.345 the format %6.3f prints 12.345 while digits (trailing zeros are removed). For example, given 12.345 the format
%.3g prints 12.3. The default precision for %e, %f and %#g is 6; for %g it %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f
is the smallest number of digits necessary to identify the value uniquely. and %#g is 6; for %g it is the smallest number of digits necessary to identify
the value uniquely.
For complex numbers, the width and precision apply to the two For complex numbers, the width and precision apply to the two
components independently and the result is parenthesized, so %f applied components independently and the result is parenthesized, so %f applied
......
...@@ -35,10 +35,11 @@ var float64info = floatInfo{52, 11, -1023} ...@@ -35,10 +35,11 @@ var float64info = floatInfo{52, 11, -1023}
// 'g' ('e' for large exponents, 'f' otherwise), or // 'g' ('e' for large exponents, 'f' otherwise), or
// 'G' ('E' for large exponents, 'f' otherwise). // 'G' ('E' for large exponents, 'f' otherwise).
// //
// The precision prec controls the number of digits // The precision prec controls the number of digits (excluding the exponent)
// (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. // printed by the 'e', 'E', 'f', 'g', and 'G' formats.
// For 'e', 'E', and 'f' it is the number of digits after the decimal point. // For 'e', 'E', and 'f' it is the number of digits after the decimal point.
// For 'g' and 'G' it is the total number of digits. // For 'g' and 'G' it is the maximum number of significant digits (trailing
// zeros are removed).
// The special precision -1 uses the smallest number of digits // The special precision -1 uses the smallest number of digits
// necessary such that ParseFloat will return f exactly. // necessary such that ParseFloat will return f exactly.
func FormatFloat(f float64, fmt byte, prec, bitSize int) string { func FormatFloat(f float64, fmt byte, prec, bitSize int) string {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment