[go] fmt.doc: formatting functions will round the number according to the specified precision

2 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
May 27, 2023, 12:44:09 PM5/27/23
to goph...@pubsubhelper.golang.org, Jabar Asadi, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

fmt.doc: formatting functions will round the number according to the specified precision

Change-Id: I8bf602a7e58595b9c264b85ab8fc1d01fae1aee4
GitHub-Last-Rev: f629ff5f4fd7f40df5cb1cb43172f0de2bf24a9a
GitHub-Pull-Request: golang/go#60472
---
M src/fmt/doc.go
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/fmt/doc.go b/src/fmt/doc.go
index 9785ed9..0846f34 100644
--- a/src/fmt/doc.go
+++ b/src/fmt/doc.go
@@ -120,6 +120,10 @@
%6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f
and %#g is 6; for %g it is the smallest number of digits necessary to identify
the value uniquely.
+If the digit immediately following the precision position is 5 or greater, the
+number is rounded up. For example, given 12.345 the format
+%.2f prints 12.35, otherwise the number is rounded down (truncated). For example,
+given 12.341 the format %.2f prints 12.34.

For complex numbers, the width and precision apply to the two
components independently and the result is parenthesized, so %f applied

To view, visit change 498875. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I8bf602a7e58595b9c264b85ab8fc1d01fae1aee4
Gerrit-Change-Number: 498875
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Jabar Asadi <jas...@d2iq.com>

Rob Pike (Gerrit)

unread,
May 27, 2023, 7:16:51 PM5/27/23
to Gerrit Bot, Jabar Asadi, goph...@pubsubhelper.golang.org, Rob Pike, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

View Change

1 comment:

  • File src/fmt/doc.go:

    • Patch Set #1, Line 123: If the digit immediately following the precision position is 5 or greater, the

      I don't know that this is true. It may depend on floating point rounding modes outside control of this package, and may also depend on later digits.

      I'd prefer we not say anything about this here.

To view, visit change 498875. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I8bf602a7e58595b9c264b85ab8fc1d01fae1aee4
Gerrit-Change-Number: 498875
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Jabar Asadi <jas...@d2iq.com>
Gerrit-CC: Martin Möhrmann <moeh...@google.com>
Gerrit-Comment-Date: Sat, 27 May 2023 23:16:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

Jabar Asadi (Gerrit)

unread,
May 28, 2023, 2:35:59 AM5/28/23
to Gerrit Bot, goph...@pubsubhelper.golang.org, Rob Pike, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Rob Pike.

View Change

1 comment:

  • File src/fmt/doc.go:

    • I don't know that this is true. […]

      I see, Thanks! I will close the PR then.

To view, visit change 498875. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I8bf602a7e58595b9c264b85ab8fc1d01fae1aee4
Gerrit-Change-Number: 498875
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Jabar Asadi <jas...@d2iq.com>
Gerrit-CC: Martin Möhrmann <moeh...@google.com>
Gerrit-Attention: Rob Pike <r...@golang.org>
Gerrit-Comment-Date: Sun, 28 May 2023 06:35:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Rob Pike <r...@golang.org>

Gopher Robot (Gerrit)

unread,
May 28, 2023, 2:45:22 AM5/28/23
to Gerrit Bot, Jabar Asadi, goph...@pubsubhelper.golang.org, Rob Pike, Martin Möhrmann, golang-co...@googlegroups.com

Gopher Robot abandoned this change.

View Change

Abandoned GitHub PR golang/go#60472 has been closed.

To view, visit change 498875. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages