aa
This commit is contained in:
@@ -37,7 +37,11 @@ var (
|
||||
|
||||
letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
flowUnitMap = map[string]string{}
|
||||
flowUnitMap = map[string]string{
|
||||
"KB": "KB",
|
||||
"MB": "MB",
|
||||
"GB": "GB",
|
||||
}
|
||||
)
|
||||
|
||||
const fileExt = ".xlsx"
|
||||
@@ -679,5 +683,38 @@ func BuildErr(errs []error) (err error) {
|
||||
}
|
||||
|
||||
func SplitFlowAndUnit(flowStr string) (flow float64, unit string) {
|
||||
for _, v := range flowUnitMap {
|
||||
if strings.Contains(flowStr, v) {
|
||||
return utils.Str2Float64WithDefault(flowStr[:len(flowStr)-2], 0), flowStr[len(flowStr)-2:]
|
||||
}
|
||||
}
|
||||
return flow, unit
|
||||
}
|
||||
|
||||
func Flow2KB(flow float64, unit string) (flowKB float64) {
|
||||
if unit == "KB" {
|
||||
return flow
|
||||
} else if unit == "MB" {
|
||||
return flow * 1024
|
||||
} else if unit == "GB" {
|
||||
return flow * 1024 * 1024
|
||||
}
|
||||
return flowKB
|
||||
}
|
||||
|
||||
func FlowKB2Other(flowKB float64) (flow float64, unit string) {
|
||||
if flowKB < 1024 {
|
||||
return flowKB, "KB"
|
||||
} else {
|
||||
flowMB := math.Round(flowKB / float64(1024))
|
||||
if flowMB < 1024 {
|
||||
return flowMB, "MB"
|
||||
} else {
|
||||
flowGB := math.Round(flowMB / float64(1024))
|
||||
if flowGB < 1024 {
|
||||
return flowGB, "GB"
|
||||
}
|
||||
}
|
||||
}
|
||||
return flow, unit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user