DirGetSize Ergebnis verkürzen

  • Hi

    Ich habe mit DirGetSize die Größe eines Verzeichnisses erhalten und sie durch 1000000 geteilt wodurch ich die MB Größe erhalten habe. Nun ist das eine ca. 11 Stellige Zahl, die ich gerne auf 3 Stellen kürzen würde. Geht das und wenn ja wie?

    Einmal editiert, zuletzt von iFreak95 (4. Juni 2012 um 21:29)

  • Du hast jetzt MB und immernoch 11 Stellen? Ich hoffe jetzt mal da gibts auch noch ein paar Stellen nach dem Komma ;). Wenn ich dich richtig verstehe solltest du wohl Round() verwenden. Und sonst musst du noch präziser werden.

    Gruss Shadowigor

  • Die zahl hat insgesamt 11 Stellen :D

    Danke ich schau mir das mal an!


    EDIT: Klappt wie gewünscht, vielen Dank!!

    • Offizieller Beitrag

    Vielleicht suchst Du sowas:

    Spoiler anzeigen
    [autoit]


    #include <String.au3>
    MsgBox(0, 'Beispiel 1', _ByteAutoSize(54225976, 0, 2, False)) ; ohne Tausendertrennzeichen

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, 'Beispiel 2', _ByteAutoSize(54225976, 0, 2, True)) ; mit Tausendertrennzeichen

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, 'Beispiel 3', _ByteAutoSize(DriveSpaceTotal('c:') * 2 ^ 20)) ; DriveSpaceTotal gibt den Wert in MByte zurück, deshalb "* 2 ^ 20"

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _ByteAutoSize($iSize[, $iRound][, $iFormat][, $bThousands])
    ; Description:: Gibt einen Bytewert in einer bestimmten Einheit zurück
    ; Parameter(s): $iSize = Größe in Byte übergeben
    ; $iRound = Anzahl der Nachkommastellen (0...8)
    ; $iFormat = bestimmt den Rückgabewert
    ; 0 = Automatisch (je nach übergebenen Wert)
    ; 1 = in Byte
    ; 2 = in KByte
    ; 3 = in MByte
    ; 4 = in GByte
    ; $bThousands = Rückgabe mit Tausendertrennzeichen (True/False)
    ; Requirement(s): #include <String.au3>
    ; Author(s): Oscar (http://www.autoit.de)
    ;===============================================================================
    Func _ByteAutoSize($iSize, $iRound = 2, $iFormat = 0, $bThousands = True)
    Local $aSize[4] = [' Byte', ' KByte', ' MByte', ' GByte'], $sReturn
    If $iFormat < 0 Or $iFormat > 4 Then $iFormat = 0
    If $iRound < 0 Or $iRound > 8 Then $iRound = 2
    If Not IsBool($bThousands) Then $bThousands = False
    $iSize = Abs($iSize)
    If $iFormat = 0 Then
    For $i = 30 To 0 Step -10
    If $iSize > (2 ^ $i) Then
    $iFormat = $i / 10 + 1
    ExitLoop
    EndIf
    Next
    EndIf
    If $iFormat = 0 Then $iFormat = 1
    $sReturn = StringFormat('%.' & $iRound & 'f', Round($iSize / (2 ^ (($iFormat - 1) * 10)), $iRound))
    If $bThousands Then $sReturn = _StringAddThousandsSep($sReturn, '.', ',')
    Return $sReturn & $aSize[$iFormat - 1]
    EndFunc ;==>_ByteAutoSize

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _StringAddThousandsSep
    ; Description ...: Returns the original numbered string with the Thousands delimiter inserted.
    ; Syntax.........: _StringAddThousandsSep($sString[, $sThousands = -1[, $sDecimal = -1]])
    ; Parameters ....: $sString - The string to be converted.
    ; $sThousands - Optional: The Thousands delimiter
    ; $sDecimal - Optional: The decimal delimiter
    ; Return values .: Success - The string with Thousands delimiter added.
    ; Author ........: SmOke_N (orignal _StringAddComma
    ; Modified.......: Valik (complete re-write, new function name)
    ; ===============================================================================================================================
    Func _StringAddThousandsSep($sString, $sThousands = -1, $sDecimal = -1)
    Local $sResult = "" ; Force string
    Local $rKey = "HKCU\Control Panel\International"
    If $sDecimal = -1 Then $sDecimal = RegRead($rKey, "sDecimal")
    If $sThousands = -1 Then $sThousands = RegRead($rKey, "sThousand")
    Local $aNumber = StringRegExp($sString, "(\D?\d+)\D?(\d*)", 1) ; This one works for negatives.
    If UBound($aNumber) = 2 Then
    Local $sLeft = $aNumber[0]
    While StringLen($sLeft)
    $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
    $sLeft = StringTrimRight($sLeft, 3)
    WEnd
    $sResult = StringTrimLeft($sResult, StringLen($sThousands)) ; Strip leading thousands separator
    If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
    EndIf
    Return $sResult
    EndFunc ;==>_StringAddThousandsSep

    [/autoit]