Skip to content

Commit

Permalink
better float formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Cable committed Mar 16, 2018
1 parent 3716f71 commit 9d76579
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions validators/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,12 @@ func stringSliceToFloatSlice(values []string) (floats []float64, err error) {
// f64 formats a float value for human reading.
// ex: 100.0 -> 100 or 100.123000 -> 100.123
func f64(f float64) string {
if f == math.MaxFloat64 || f == -math.MaxFloat64 {
return fmt.Sprint(f)
switch f {
case math.MaxFloat64:
return "max float64"
case -math.MaxFloat64:
return "min float64"
default:
return strconv.FormatFloat(f, 'f', -1, 64)
}
return strconv.FormatFloat(f, 'f', -1, 64)
}

0 comments on commit 9d76579

Please sign in to comment.