We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 269a863 commit 9ec74abCopy full SHA for 9ec74ab
3 files changed
ftoa.go
@@ -6,6 +6,9 @@ import (
6
)
7
8
func stripTrailingZeros(s string) string {
9
+ if !strings.ContainsRune(s, '.') {
10
+ return s
11
+ }
12
offset := len(s) - 1
13
for offset > 0 {
14
if s[offset] == '.' {
ftoa_test.go
@@ -14,6 +14,7 @@ import (
func TestFtoa(t *testing.T) {
15
testList{
16
{"200", Ftoa(200), "200"},
17
+ {"20", Ftoa(20.0), "20"},
18
{"2", Ftoa(2), "2"},
19
{"2.2", Ftoa(2.2), "2.2"},
20
{"2.02", Ftoa(2.02), "2.02"},
@@ -24,6 +25,7 @@ func TestFtoa(t *testing.T) {
24
25
func TestFtoaWithDigits(t *testing.T) {
26
27
{"1.23, 0", FtoaWithDigits(1.23, 0), "1"},
28
+ {"20, 0", FtoaWithDigits(20.0, 0), "20"},
29
{"1.23, 1", FtoaWithDigits(1.23, 1), "1.2"},
30
{"1.23, 2", FtoaWithDigits(1.23, 2), "1.23"},
31
{"1.23, 3", FtoaWithDigits(1.23, 3), "1.23"},
si_test.go
@@ -126,3 +126,20 @@ func BenchmarkParseSI(b *testing.B) {
126
ParseSI("2.2346ZB")
127
}
128
129
+
130
+// There was a report that zeroes were being truncated incorrectly
131
+func TestBug106(t *testing.T) {
132
+ tests := []struct{
133
+ in float64
134
+ want string
135
+ }{
136
+ {20.0, "20 U"},
137
+ {200.0, "200 U"},
138
139
140
+ for _, test := range tests {
141
+ if got :=SIWithDigits(test.in, 0, "U") ; got != test.want {
142
+ t.Errorf("on %f got %v, want %v", test.in, got, test.want);
143
144
145
+}
0 commit comments