(precision int)
| 39 | } |
| 40 | |
| 41 | func (b ByteSize) StringWithPrecision(precision int) string { |
| 42 | |
| 43 | format := fmt.Sprintf("%%.%vf", precision) |
| 44 | |
| 45 | switch { |
| 46 | case b >= YB: |
| 47 | return fmt.Sprintf(format+"YB", b/YB) |
| 48 | case b >= ZB: |
| 49 | return fmt.Sprintf(format+"ZB", b/ZB) |
| 50 | case b >= EB: |
| 51 | return fmt.Sprintf(format+"EB", b/EB) |
| 52 | case b >= PB: |
| 53 | return fmt.Sprintf(format+"PB", b/PB) |
| 54 | case b >= TB: |
| 55 | return fmt.Sprintf(format+"TB", b/TB) |
| 56 | case b >= GB: |
| 57 | return fmt.Sprintf(format+"GB", b/GB) |
| 58 | case b >= MB: |
| 59 | return fmt.Sprintf(format+"MB", b/MB) |
| 60 | case b >= KB: |
| 61 | return fmt.Sprintf(format+"KB", b/KB) |
| 62 | } |
| 63 | return fmt.Sprintf("%.0fB", b) |
| 64 | } |
| 65 | |
| 66 | func main() { |
| 67 | fmt.Println(YB, ByteSize(1e13)) |
no outgoing calls
no test coverage detected