Skip to content

Commit 283d371

Browse files
committed
Merge pull request #51 from prometheus/sample-formatting
Better sample value string formatting.
2 parents 000337c + 4a842c5 commit 283d371

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

model/samplevalue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package model
1515

1616
import (
1717
"fmt"
18+
"strconv"
1819
)
1920

2021
// A SampleValue is a representation of a value for a given sample at a given
@@ -28,9 +29,9 @@ func (v SampleValue) Equal(o SampleValue) bool {
2829

2930
// MarshalJSON implements json.Marshaler.
3031
func (v SampleValue) MarshalJSON() ([]byte, error) {
31-
return []byte(fmt.Sprintf(`"%f"`, v)), nil
32+
return []byte(fmt.Sprintf(`"%s"`, v)), nil
3233
}
3334

3435
func (v SampleValue) String() string {
35-
return fmt.Sprint(float64(v))
36+
return strconv.FormatFloat(float64(v), 'f', -1, 64)
3637
}

model/timestamp.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
package model
1515

1616
import (
17-
"fmt"
17+
"strconv"
18+
1819
native_time "time"
1920
)
2021

@@ -81,7 +82,7 @@ func (t Timestamp) UnixNano() int64 {
8182

8283
// String returns a string representation of the timestamp.
8384
func (t Timestamp) String() string {
84-
return fmt.Sprintf("%f", float64(t)/float64(second))
85+
return strconv.FormatFloat(float64(t)/float64(second), 'f', -1, 64)
8586
}
8687

8788
func (t Timestamp) MarshalJSON() ([]byte, error) {

0 commit comments

Comments
 (0)