summaryrefslogtreecommitdiffstats
path: root/pkg/plot/format.go
blob: 03d19f049717612cccc783448f3f13cda9deb797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package plot

import "strconv"

const maxDigits = 7

// Ff formats a float
func Ff(x float64) []rune {
	minExact := strconv.FormatFloat(x, 'g', -1, 64)
	fixed := strconv.FormatFloat(x, 'g', maxDigits, 64)
	if len(minExact) < len(fixed) {
		return []rune(minExact)
	}
	return []rune(fixed)
}

// Fi formats an int
func Fi(x int) []rune {
	return []rune(strconv.FormatInt(int64(x), 10))
}