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.
[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"
Last edited by kounger on July 6th, 2018, 9:23 pm, edited 1 time in total.
Although your code works well, I'm not sure at all it worth to use five measures to achieve what two options on a String meter can easily do. Beside the AutoScale, the number of decimals can also be set onto a String meter.
balala wrote:Although your code works well, I'm not sure at all it worth to use five measures to achieve what two options on a String meter can easily do. Beside the AutoScale, the number of decimals can also be set onto a String meter.
Oh. It even says so in the box that it lets you set the number of decimals along with it. Thanks for clearing that up. That's a more elegant solution of course.
kounger wrote:Oh. It even says so in the box that it lets you set the number of decimals along with it. Thanks for clearing that up. That's a more elegant solution of course.
Don't misunderstand me, I don't want to subestimate your code, which works perfectly. Its only disadvantage is the size: it is too long for what it does.
Plus there is one more thing you have to know about: the Round function also can be used to get the same result (last function in this list).
But if you're a beginner with Rainmeter (what I think you are), I want to congratulate you, because your code definitely does what it is created for.
balala wrote:Don't misunderstand me, I don't want to subestimate your code, which works perfectly. Its only disadvantage is the size: it is too long for what it does.
Plus there is one more thing you have to know about: the Round function also can be used to get the same result (last function in this list).
But if you're a beginner with Rainmeter (what I think you are), I want to congratulate you, because your code definitely does what it is created for.
Yeah. I already replaced the code in my skin with the simpler solution. I don't know how I skipped over this when I read the instructions. I was so certain for some reason that this was not possible without some extra coding. Also the Formula with the Floor function actually does what I intended it to do. I just tried to copy what Windows does with file sizes and it actually rounds everything down while the Round function rounds up when the next digit is 5 or higher.
kounger wrote:Also the Formula with the Floor function actually does what I intended it to do. I just tried to copy what Windows does with file sizes and it actually rounds everything down while the Round function rounds up when the next digit is 5 or higher.
Yeah, this is the essence of the Floor formula.
But don't be disappointed and keep working. Rainmeter has a lot of tricks which you can work with.
balala wrote:Yeah, this is the essence of the Floor formula.
But don't be disappointed and keep working. Rainmeter has a lot of tricks which you can work with.
I used this in my script, very good!!! I had an issue where I needed to set the Measure to the right size from bytes and didn't need to create a meter as I am outputting this info into a ToolTip.
I want to throw in a solution provided by user smurfier in this thread/post about the recycle bin introducing the "scary math" for getting scale and the scaled size for a number of bytes.