blob: c76190b106716add410d2b5a5f66d0ed0719f102 [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001package humanize
2
3import "strconv"
4
5func stripTrailingZeros(s string) string {
6 offset := len(s) - 1
7 for offset > 0 {
8 if s[offset] == '.' {
9 offset--
10 break
11 }
12 if s[offset] != '0' {
13 break
14 }
15 offset--
16 }
17 return s[:offset+1]
18}
19
20// Ftoa converts a float to a string with no trailing zeros.
21func Ftoa(num float64) string {
22 return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64))
23}