Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix filesize formatting edge cases

1024 bytes should be "1.0 KiB" not "1024.0 B"
Cette révision appartient à :
sfan5 2017-05-07 21:06:20 +02:00
Parent ac33a734fd
révision a17813f01b

Voir le fichier

@ -7,16 +7,16 @@ import (
func FormatFilesize(bytes int64) string { func FormatFilesize(bytes int64) string {
var unit string var unit string
var value float64 var value float64
if bytes > 1024*1024*1024*1024 { if bytes >= 1024*1024*1024*1024 {
unit = "TiB" unit = "TiB"
value = float64(bytes) / (1024*1024*1024*1024) value = float64(bytes) / (1024*1024*1024*1024)
} else if bytes > 1024*1024*1024 { } else if bytes >= 1024*1024*1024 {
unit = "GiB" unit = "GiB"
value = float64(bytes) / (1024*1024*1024) value = float64(bytes) / (1024*1024*1024)
} else if bytes > 1024*1024 { } else if bytes >= 1024*1024 {
unit = "MiB" unit = "MiB"
value = float64(bytes) / (1024*1024) value = float64(bytes) / (1024*1024)
} else if bytes > 1024 { } else if bytes >= 1024 {
unit = "KiB" unit = "KiB"
value = float64(bytes) / (1024) value = float64(bytes) / (1024)
} else { } else {