Files
opencloud/vendor/github.com/gookit/goutil/mathutil/number.go
dependabot[bot] 5ebc596352 Bump github.com/gookit/config/v2 from 2.1.8 to 2.2.2
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.1.8 to 2.2.2.
- [Release notes](https://github.com/gookit/config/releases)
- [Commits](https://github.com/gookit/config/compare/v2.1.8...v2.2.2)

---
updated-dependencies:
- dependency-name: github.com/gookit/config/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:54:58 +02:00

38 lines
888 B
Go

package mathutil
import (
"fmt"
"time"
"github.com/gookit/goutil/basefn"
)
// IsNumeric returns true if the given character is a numeric, otherwise false.
func IsNumeric(c byte) bool {
return c >= '0' && c <= '9'
}
// Percent returns a values percent of the total
func Percent(val, total int) float64 {
if total == 0 {
return float64(0)
}
return (float64(val) / float64(total)) * 100
}
// ElapsedTime calc elapsed time 计算运行时间消耗 单位 ms(毫秒)
func ElapsedTime(startTime time.Time) string {
return fmt.Sprintf("%.3f", time.Since(startTime).Seconds()*1000)
}
// DataSize format value to data size string. eg: 1024 => 1KB, 1024*1024 => 1MB
// alias format.DataSize()
func DataSize(size uint64) string {
return basefn.DataSize(size)
}
// HowLongAgo calc time. alias format.HowLongAgo()
func HowLongAgo(sec int64) string {
return basefn.HowLongAgo(sec)
}