2019-01-18 18:28:35 +00:00
|
|
|
package api
|
|
|
|
|
2019-01-18 18:36:49 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
2019-01-18 18:28:35 +00:00
|
|
|
|
2019-01-18 18:36:49 +00:00
|
|
|
// formatFloat converts the floating-point number f to a string,
|
|
|
|
// after rounding it to the passed unit.
|
|
|
|
//
|
|
|
|
// Uses 'f' format (-ddd.dddddd, no exponent), and uses at most
|
|
|
|
// maxPrec digits after the decimal point.
|
|
|
|
func formatFloat(f float64, maxPrec int) string {
|
|
|
|
v := strconv.FormatFloat(f, 'f', -1, 64)
|
|
|
|
|
|
|
|
idx := strings.LastIndex(v, ".")
|
|
|
|
if idx == -1 {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
sublen := idx + maxPrec + 1
|
|
|
|
if sublen > len(v) {
|
|
|
|
sublen = len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return v[:sublen]
|
|
|
|
}
|
2022-08-17 16:26:34 +00:00
|
|
|
|
|
|
|
// pointerOf returns a pointer to a.
|
|
|
|
func pointerOf[A any](a A) *A {
|
|
|
|
return &a
|
|
|
|
}
|