Skip to content

Commit 9d76579

Browse files
author
Benjamin Cable
committed
better float formats
1 parent 3716f71 commit 9d76579

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

validators/validators.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,12 @@ func stringSliceToFloatSlice(values []string) (floats []float64, err error) {
326326
// f64 formats a float value for human reading.
327327
// ex: 100.0 -> 100 or 100.123000 -> 100.123
328328
func f64(f float64) string {
329-
if f == math.MaxFloat64 || f == -math.MaxFloat64 {
330-
return fmt.Sprint(f)
329+
switch f {
330+
case math.MaxFloat64:
331+
return "max float64"
332+
case -math.MaxFloat64:
333+
return "min float64"
334+
default:
335+
return strconv.FormatFloat(f, 'f', -1, 64)
331336
}
332-
return strconv.FormatFloat(f, 'f', -1, 64)
333337
}

0 commit comments

Comments
 (0)