summaryrefslogtreecommitdiffstats
path: root/modules/base/tool.go
diff options
context:
space:
mode:
author赵智超 <1012112796@qq.com>2020-09-16 12:07:18 +0800
committerGitHub <noreply@github.com>2020-09-16 00:07:18 -0400
commita9decf0dacb56e57024ef7c5a0ade7fdcc56407e (patch)
treef6d1d48eaa324530b93af2780ff2297e11b39e25 /modules/base/tool.go
parentd8b5235dedbb69812aeb43218a8d35938259a1c3 (diff)
downloadgitea-a9decf0dacb56e57024ef7c5a0ade7fdcc56407e.tar.gz
gitea-a9decf0dacb56e57024ef7c5a0ade7fdcc56407e.zip
Use a simple format for the big number on ui (#12822)
* Use a simple format for the big number on ui Signed-off-by: a1012112796 <1012112796@qq.com> * make fmt * Apply review suggestion @silverwind * Change name 2 * make fmt Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r--modules/base/tool.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index e1a1b661be..a21fd9b0f4 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -420,3 +420,27 @@ func SetupGiteaRoot() string {
}
return giteaRoot
}
+
+// FormatNumberSI format a number
+func FormatNumberSI(data interface{}) string {
+ var num int64
+ if num1, ok := data.(int64); ok {
+ num = num1
+ } else if num1, ok := data.(int); ok {
+ num = int64(num1)
+ } else {
+ return ""
+ }
+
+ if num < 1000 {
+ return fmt.Sprintf("%d", num)
+ } else if num < 1000000 {
+ num2 := float32(num) / float32(1000.0)
+ return fmt.Sprintf("%.1fk", num2)
+ } else if num < 1000000000 {
+ num2 := float32(num) / float32(1000000.0)
+ return fmt.Sprintf("%.1fM", num2)
+ }
+ num2 := float32(num) / float32(1000000000.0)
+ return fmt.Sprintf("%.1fG", num2)
+}