diff options
Diffstat (limited to 'pkg/plot/format.go')
-rw-r--r-- | pkg/plot/format.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pkg/plot/format.go b/pkg/plot/format.go new file mode 100644 index 0000000..f1175dd --- /dev/null +++ b/pkg/plot/format.go @@ -0,0 +1,15 @@ +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) +} |