aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/fmt/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/fmt/format.go')
-rw-r--r--libgo/go/fmt/format.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go
index 74e600c..4d12f82 100644
--- a/libgo/go/fmt/format.go
+++ b/libgo/go/fmt/format.go
@@ -536,6 +536,7 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
tail := tailBuf[:0]
hasDecimalPoint := false
+ sawNonzeroDigit := false
// Starting from i = 1 to skip sign at num[0].
for i := 1; i < len(num); i++ {
switch num[i] {
@@ -552,10 +553,20 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
}
fallthrough
default:
- digits--
+ if num[i] != '0' {
+ sawNonzeroDigit = true
+ }
+ // Count significant digits after the first non-zero digit.
+ if sawNonzeroDigit {
+ digits--
+ }
}
}
if !hasDecimalPoint {
+ // Leading digit 0 should contribute once to digits.
+ if len(num) == 2 && num[1] == '0' {
+ digits--
+ }
num = append(num, '.')
}
for digits > 0 {