diff options
| author | Bobby <[email protected]> | 2025-07-07 22:57:31 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-07-07 22:57:31 +0530 |
| commit | 52a0248c1c81a14699b3d33ba7efe0c56bbe7477 (patch) | |
| tree | 02d35fee769d518beb5dd01715e84d13ea421d51 /utils/format/format.go | |
| parent | b6a04140f2668a0dcae4befcd272e05b75bd14e5 (diff) | |
| download | imageboard-52a0248c1c81a14699b3d33ba7efe0c56bbe7477.tar.xz imageboard-52a0248c1c81a14699b3d33ba7efe0c56bbe7477.zip | |
massive y2k retro overhaul with sidebar, context processors, and proper database organization
Diffstat (limited to 'utils/format/format.go')
| -rw-r--r-- | utils/format/format.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/utils/format/format.go b/utils/format/format.go new file mode 100644 index 0000000..53c813e --- /dev/null +++ b/utils/format/format.go @@ -0,0 +1,27 @@ +package format + +import "fmt" + +func FileSize(size int64) string { + const unit = 1024 + if size < unit { + return fmt.Sprintf("%d B", size) + } + div, exp := int64(unit), 0 + for n := size / unit; n >= unit; n /= unit { + div *= unit + exp++ + } + + return fmt.Sprintf("%.2f %sB", float64(size)/float64(div), "KMGTPE"[exp:exp+1]) +} + +func Count(count int64) string { + if count < 1000 { + return fmt.Sprintf("%d", count) + } else if count < 1000000 { + return fmt.Sprintf("%.1fK", float64(count)/1000) + } else { + return fmt.Sprintf("%.1fM", float64(count)/1000000) + } +} |
