blob: b06cf8c9a595174a6bd612c709c9b3899d5f7268 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package utils
import (
"math"
)
var (
KB = uint64(math.Pow(2, 10))
MB = uint64(math.Pow(2, 20))
GB = uint64(math.Pow(2, 30))
TB = uint64(math.Pow(2, 40))
)
func CelsiusToFahrenheit(c int) int {
return c*9/5 + 32
}
func BytesToKB(b uint64) float64 {
return float64(b) / float64(KB)
}
func BytesToMB(b uint64) float64 {
return float64(b) / float64(MB)
}
func BytesToGB(b uint64) float64 {
return float64(b) / float64(GB)
}
func BytesToTB(b uint64) float64 {
return float64(b) / float64(TB)
}
func ConvertBytes(b uint64) (float64, string) {
switch {
case b < KB:
return float64(b), "B"
case b < MB:
return BytesToKB(b), "KB"
case b < GB:
return BytesToMB(b), "MB"
case b < TB:
return BytesToGB(b), "GB"
default:
return BytesToTB(b), "TB"
}
}
|