Skip to content

Commit 6e1f2b6

Browse files
committed
fixes #36562
1 parent 6768429 commit 6e1f2b6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/fmt/fmt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ var fmtTests = []struct {
470470
{"%#.4g", 1.2, "1.200"},
471471
{"%#.4g", 0.12, "0.1200"},
472472
{"%#.4g", 10.2, "10.20"},
473-
{"%#.4g", 0.0, "0.0000"},
474-
{"%#.4g",0.012,"0.01200"},
473+
{"%#.4g", 0.0, "0.000"},
474+
{"%#.4g", 0.012, "0.01200"},
475475
{"%#.0f", 123.0, "123."},
476476
{"%#.0e", 123.0, "1.e+02"},
477477
{"%#.0x", 123.0, "0x1.p+07"},

src/fmt/format.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
563563
}
564564
}
565565
if !hasDecimalPoint {
566+
// 0 should contribute once to digits
567+
if num[1] == '0' && len(num) == 2 {
568+
digits--
569+
}
566570
num = append(num, '.')
567571
}
568572
for digits > 0 {

0 commit comments

Comments
 (0)