Merge pull request #51 from prometheus/sample-formatting

Better sample value string formatting.
This commit is contained in:
juliusv 2015-01-26 01:41:16 +01:00
commit 283d371002
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@ package model
import ( import (
"fmt" "fmt"
"strconv"
) )
// A SampleValue is a representation of a value for a given sample at a given // 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 {
// MarshalJSON implements json.Marshaler. // MarshalJSON implements json.Marshaler.
func (v SampleValue) MarshalJSON() ([]byte, error) { func (v SampleValue) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%f"`, v)), nil return []byte(fmt.Sprintf(`"%s"`, v)), nil
} }
func (v SampleValue) String() string { func (v SampleValue) String() string {
return fmt.Sprint(float64(v)) return strconv.FormatFloat(float64(v), 'f', -1, 64)
} }

View File

@ -14,7 +14,8 @@
package model package model
import ( import (
"fmt" "strconv"
native_time "time" native_time "time"
) )
@ -81,7 +82,7 @@ func (t Timestamp) UnixNano() int64 {
// String returns a string representation of the timestamp. // String returns a string representation of the timestamp.
func (t Timestamp) String() string { func (t Timestamp) String() string {
return fmt.Sprintf("%f", float64(t)/float64(second)) return strconv.FormatFloat(float64(t)/float64(second), 'f', -1, 64)
} }
func (t Timestamp) MarshalJSON() ([]byte, error) { func (t Timestamp) MarshalJSON() ([]byte, error) {