Language: Add BytesToString
This commit is contained in:
parent
bdae2d5ee5
commit
7d9beaceca
@ -191,4 +191,15 @@ Public Class Utils
|
|||||||
|
|
||||||
Return False
|
Return False
|
||||||
End Function
|
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
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user