sampler-fork/component/util/format.go

27 lines
462 B
Go
Raw Normal View History

2019-03-26 03:29:23 +00:00
package util
import (
"fmt"
"math"
"strconv"
)
func FormatValue(value float64, scale int) string {
if math.Abs(value) == math.MaxFloat64 {
return "Inf"
} else {
format := "%." + strconv.Itoa(scale) + "f"
return fmt.Sprintf(format, value)
}
}
func FormatValueWithSign(value float64, scale int) string {
if value == 0 {
return " 0"
} else if value > 0 {
return "+" + FormatValue(value, scale)
} else {
return FormatValue(value, scale)
}
}