diff --git a/Modules.Language/Utils.vb b/Modules.Language/Utils.vb index 153e767f..129fcb1c 100644 --- a/Modules.Language/Utils.vb +++ b/Modules.Language/Utils.vb @@ -191,4 +191,15 @@ Public Class Utils Return False End Function + + Public Shared Function BytesToString(ByteCount As Long) As String + Dim oSuffixes As New List(Of String) From {"B", "KB", "MB", "GB", "TB", "PB", "EB"} + If ByteCount = 0 Then + Return "0" & oSuffixes.First() + End If + Dim oBytes = Math.Abs(ByteCount) + Dim oIndex = Convert.ToInt32(Math.Floor(Math.Log(oBytes, 1024))) + Dim oNum = Math.Round(oBytes / Math.Pow(1024, oIndex), 1) + Return (Math.Sign(ByteCount) * oNum).ToString() & oSuffixes.Item(oIndex) + End Function End Class