func ExampleFormatPrefix() { s1 := strconv.FormatPrefix(strconv.Tebi, strconv.SI, 3) fmt.Printf("1 tebibyte in SI: %sB\n", s1) s2 := strconv.FormatPrefix(strconv.Tera, strconv.IEC, 3) fmt.Printf("1 terabyte in IEC: %sB\n", s2) // Output: // 1 tebibyte in SI: 1.100TB // 1 terabyte in IEC: 931.323GiB }
func getName(f string, l, n int) string { var sn string switch n { case 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12: s := fmt.Sprintf("%e", float64(n)) re := regexp.MustCompile("\\.0*e\\+0*") sn = re.ReplaceAllString(s, "e") default: s := strconv.FormatPrefix(float64(n), strconv.Base1024, 2) sn = strings.Replace(s, ".00", "", -1) } return fmt.Sprintf("%s:%d:%s", path.Base(f), l, sn) }