Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

Print File Size

, 18 Jul 2010
Rate this:
Please Sign up or sign in to vote.
Here is an alternate I like to use. Private Function TranslateFileSize(ByVal size As Double) As String Try Dim filesizename() As String = {" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"} Dim pow As Double = Math.Floor(Math.Log(size,...
Here is an alternate I like to use.
 
    Private Function TranslateFileSize(ByVal size As Double) As String
        Try
            Dim filesizename() As String = {" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"}
            Dim pow As Double = Math.Floor(Math.Log(size, 1024))
            Return String.Concat(Math.Round(size / Math.Pow(1024, pow), 2), " ", filesizename(CInt(pow)))
        Catch ex As Exception
            Return size
        End Try
    End Function

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SSDiver2112
Software Developer
United States United States
I first got hooked on programing with the TI994A. After it finally lost all support I reluctantly moved to the Apple IIe. Thank You BeagleBros for getting me through. I wrote programs for my Scuba buisness during this time. Currently I am a Database manager and software developer. I started with VBA and VB6 and now having fun with VB.NET

Comments and Discussions

 
GeneralReason for my vote of 5 Nice implementation! PinmemberJ. Dunlap18-Jul-10 8:20 
GeneralYour solution is quite elegant, I like it, although it takes... Pinmemberchkmos18-Jul-10 6:03 
Your solution is quite elegant, I like it, although it takes slightly more computation. Thanks.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 18 Jul 2010
Article Copyright 2010 by SSDiver2112
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid