hakk

software development, devops, and other drivel
Tree lined path

size

Golang Convert File Size to a human friendly format

Get file size in human-readable units like kilobytes (KB), Megabytes (MB) or GigaBytes (GB) 1 KilloByte == 1024 Bytes 1 Megabyte == 1024*1024 Bytes 1 GigaByte == 102410241024 Bytes package main import ( "fmt" "log" "math" "os" "strconv" ) var ( suffixes [5]string ) func Round(val float64, roundOn float64, places int ) (newVal float64) { var round float64 pow := math.Pow(10, float64(places)) digit := pow * val _, div := math. Read more...