From cab69263385e3a82fd2ba663f0e50480a7bb0882 Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Fri, 13 May 2016 19:09:14 -0400 Subject: [PATCH] Use floating points for download sizes --- queue/queue.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/queue/queue.go b/queue/queue.go index e4b88cb..38ed7d9 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -50,7 +50,7 @@ type Queue struct { lock sync.RWMutex } -var prettyBytesValues = []int64{ +var prettyBytesValues = []float64{ 1024, 1024 * 1024, 1024 * 1024 * 1024, @@ -68,8 +68,8 @@ var prettyBytesNames = []string{ "EiB", } -func prettyBytes(bytes int64) string { - output := strconv.FormatInt(bytes, 10) + "B" +func prettyBytes(bytes float64) string { + output := strconv.FormatFloat(bytes, 'f', 2, 64) + "B" for i, divisor := range prettyBytesValues { newBytes := bytes / divisor if newBytes > 1024 { @@ -80,7 +80,7 @@ func prettyBytes(bytes int64) string { break } - output = strconv.FormatInt(newBytes, 10) + prettyBytesNames[i] + output = strconv.FormatFloat(newBytes, 'f', 2, 64) + prettyBytesNames[i] } return output @@ -272,7 +272,7 @@ func (q *Queue) downloadTorrents(torrents []rtorrent.Torrent) { } go func(torrentFilePath string, downloadPath string, torrent rtorrent.Torrent) { - q.logger.Printf("Downloading '%s' (%s) to '%s' (%s) %s", torrent.Name, torrentFilePath, downloadPath, destDownloadPath, prettyBytes(int64(torrent.Size))) + q.logger.Printf("Downloading '%s' (%s) to '%s' (%s) %s", torrent.Name, torrentFilePath, downloadPath, destDownloadPath, prettyBytes(float64(torrent.Size))) err := q.sftpClient.Mirror(torrent.Path, downloadPath) if err != nil { q.logger.Printf("Failed to download '%s' to '%s' error '%s'", torrent.Path, downloadPath, err)