Converting Bytes (AutoScale Alternative)
Posted: July 6th, 2018, 8:08 pm
This is an alternative to AutoScale with the difference that the Byte value will be displayed with two digits after the decimal point. This is how Windows displays file and folder sizes.
Code: Select all
[Variables]
Bytes=8618111
;This will be converted to 8.21 MB
;Determines into which unit #Bytes# will be converted. This will be the first unit where the number value is smaller than 1024.
[CalcSizeConvClass]
Measure=Calc
Formula=(Floor(#Bytes# / 1024) = 0 ? 0 : (Floor(#Bytes# / (1024**2)) = 0 ? 1 : (Floor(#Bytes# / (1024**3)) = 0 ? 2 : (Floor(#Bytes# / (1024**4)) = 0 ? 3 : (Floor(#Bytes# / (1024**5)) = 0 ? 4 : (Floor(#Bytes# / (1024**6)) = 0 ? 5 : 6))))))
IfCondition=(CalcSizeConvClass = 0)
IfTrueAction=[!SetOption StringSizeUnit String "Bytes"]
IfCondition2=(CalcSizeConvClass = 1)
IfTrueAction2=[!SetOption StringSizeUnit String "KB"]
IfCondition3=(CalcSizeConvClass = 2)
IfTrueAction3=[!SetOption StringSizeUnit String "MB"]
IfCondition4=(CalcSizeConvClass = 3)
IfTrueAction4=[!SetOption StringSizeUnit String "GB"]
IfCondition5=(CalcSizeConvClass = 4)
IfTrueAction5=[!SetOption StringSizeUnit String "TB"]
IfCondition6=(CalcSizeConvClass = 5)
IfTrueAction6=[!SetOption StringSizeUnit String "PB"]
IfCondition7=(CalcSizeConvClass = 6)
IfTrueAction7=[!SetOption StringSizeUnit String "ERROR"][!Log "More than 1024 PB can't be displayed." Error]
DynamicVariables=1
;Bytes, KB, MB, GB, TB, PB or ERROR as defined by the IfConditions
[StringSizeUnit]
Measure=String
DynamicVariables=1
;CalcSizeConvClass defines how often #Bytes# has to be divided by 1024
[CalcSizeConversion]
Measure=Calc
Formula=#Bytes# / (1024 ** [CalcSizeConvClass])
DynamicVariables=1
;Rounded down to 2 digits after the decimal point.
;For 3 digits change both 100s to 1000s.
[CalcSizeRound]
Measure=Calc
Formula=Floor([CalcSizeConversion] * 100) / 100
DynamicVariables=1
;CalcSizeRound as string to not lose the two digits after the decimal point.
[CalcSizeRoundString]
Measure=String
String=[CalcSizeRound]
DynamicVariables=1
[MeterSize]
Meter=String
MeasureName=CalcSizeRoundString
MeasureName2=StringSizeUnit
X=10
Y=10
FontFace=Trebuchet MS
FontSize=9
FontColor=255,255,255,255
StringAlign=LEFT
AntiAlias=1
Text="Size: %1 %2"