/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Friday, August 2, 2013

Using Java Script Bytes Conversion


Function ConvertBytes(ByRef anBytes)
    Dim lnSize          ' File Size To be returned
    Dim lsType          ' Type of measurement (Bytes, KB, MB, GB, TB)
   
    Const lnBYTE = 1
    Const lnKILO = 1024                     ' 2^10
    Const lnMEGA = 1048576                  ' 2^20
    Const lnGIGA = 1073741824               ' 2^30
    Const lnTERA = 1099511627776            ' 2^40
 
 
 
    '    Const lnPETA = 1.12589990684262E+15        ' 2^50
    '    Const lnEXA = 1.15292150460685E+18        ' 2^60
    '    Const lnZETTA = 1.18059162071741E+21    ' 2^70
    '    Const lnYOTTA = 1.20892581961463E+24    ' 2^80
   
    If anBytes = "" Or Not IsNumeric(anBytes) Then Exit Function
   
    If anBytes < 0 Then Exit Function  

'    If anBytes < lnKILO Then
'        ' ByteConversion
'        lnSize = anBytes
'        lsType = "bytes"
'    Else      
        If anBytes < lnMEGA Then
            ' KiloByte Conversion
            lnSize = (anBytes / lnKILO)
            lsType = "kb"
        ElseIf anBytes < lnGIGA Then
            ' MegaByte Conversion
            lnSize = (anBytes / lnMEGA)
            lsType = "mb"
        ElseIf anBytes < lnTERA Then
            ' GigaByte Conversion
            lnSize = (anBytes / lnGIGA)
            lsType = "gb"
        Else
            ' TeraByte Conversion
            lnSize = (anBytes / lnTERA)
            lsType = "tb"
        End If
'    End If
    ' Remove fraction
    'lnSize = CLng(lnSize)
    lnSize = FormatNumber(lnSize, 2, True, False, True)
   
    ' Return the results
    ConvertBytes = lnSize & " " & lsType
End Function


Function ConvertBytes1(ByRef anBytes)
if anBytes <= 1024 then
response.write anBytes & " KB"
else
anBytes = anBytes/1024
response.write anBytes & " MB"
end if
End Function


 public string ConvertBytes(int anBytes)
    {
        if (anBytes == 0)
        {
           
        }

        return "";
    }


 //File Size To be returned
    string lnSize;
    // Type of measurement (Bytes, KB, MB, GB, TB)
    string lsType;
    public const int lnBYTE = 1;
    //2^10
    public const int lnKILO = 1024;
    //2^20
    public const int lnMEGA = 1048576;
    //2^30
    public const int lnGIGA = 1073741824;
    //2^40
    public const long lnTERA = 1099511627776;
    //2^50
    public const double lnPETA = 1.12589990684262E+15;
    //2^60
    public const double lnEXA = 1.15292150460685E+18;
    //2^70
    public const double lnZETTA = 1.18059162071741E+21;
    //2^80
    public const double lnYOTTA = 1.20892581961463E+24;

No comments:

Post a Comment

My Blog List