From 4a842c5da0e6ba5f9cff4891a4f867c30251c65a Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 25 Jan 2015 23:52:11 +0100 Subject: [PATCH] Better sample value string formatting. This forces a float format without exponent that uses the minimum number of digits necessary to display a given sample value. --- model/samplevalue.go | 5 +++-- model/timestamp.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/model/samplevalue.go b/model/samplevalue.go index 72445cc..eb8dd3a 100644 --- a/model/samplevalue.go +++ b/model/samplevalue.go @@ -15,6 +15,7 @@ package model import ( "fmt" + "strconv" ) // 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. 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 { - return fmt.Sprint(float64(v)) + return strconv.FormatFloat(float64(v), 'f', -1, 64) } diff --git a/model/timestamp.go b/model/timestamp.go index e0c6dd4..4c8fcf8 100644 --- a/model/timestamp.go +++ b/model/timestamp.go @@ -14,7 +14,8 @@ package model import ( - "fmt" + "strconv" + native_time "time" ) @@ -81,7 +82,7 @@ func (t Timestamp) UnixNano() int64 { // String returns a string representation of the timestamp. 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) {