github.com/nsqio/nsq@v1.3.0/internal/stringy/template.go (about) 1 package stringy 2 3 import ( 4 "fmt" 5 ) 6 7 func NanoSecondToHuman(v float64) string { 8 var suffix string 9 switch { 10 case v > 1000000000: 11 v /= 1000000000 12 suffix = "s" 13 case v > 1000000: 14 v /= 1000000 15 suffix = "ms" 16 case v > 1000: 17 v /= 1000 18 suffix = "us" 19 default: 20 suffix = "ns" 21 } 22 return fmt.Sprintf("%0.1f%s", v, suffix) 23 }