Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.82 KB | None | 0 0
  1. Sub Main
  2.     Dim rnd As New Random
  3.     Dim numbers=Enumerable.Range(0,18).Select(Function(n) Math.Pow(10,n))
  4.     numbers= numbers.Concat(numbers.Select(Function(x) x+rnd.Next(0,500))).OrderBy(Function(x) x).ToArray.Dump("Numbers")
  5.     numbers.select(Function(n) New With {.Size=BytesToString(CLng(n)),.Number=n.ToString("n0")}).Dump("Log10")
  6.    
  7.    
  8.    
  9.    
  10. End Sub
  11.  
  12. ' Define other methods and classes here
  13. Private  Function BytesToString(ByVal byteCount As Long) As String
  14.     Dim suf As String() = {"B", "KB", "MB", "GB", "TB", "PB", "EB"}
  15.     If byteCount = 0 Then Return "0" & suf(0)
  16.     Dim bytes As Long = Math.Abs(byteCount)
  17.     Dim place As Integer = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)))
  18.     Dim num As Double = Math.Round(bytes / Math.Pow(1024, place), 1)
  19.     Return (Math.Sign(byteCount) * num).ToString() & suf(place)
  20. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement