| khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | package humanize |
| 2 | |||||
| 3 | import "strconv" | ||||
| 4 | |||||
| 5 | func 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. | ||||
| 21 | func Ftoa(num float64) string { | ||||
| 22 | return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64)) | ||||
| 23 | } | ||||