template.go 330 B

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