It is currently April 18th, 2024, 6:08 pm

Trailing Zeros

General topics related to Rainmeter.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Trailing Zeros

Post by Resike »

Is there any way to convert a variable to always show the exact number of decimals?

From: 1.1
To 1.1000
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

I saw that function however i can't really make it work, after a Calc function.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike wrote: I saw that function however i can't really make it work, after a Calc function.
I don't really follow. There is no mathematical difference between 1.1 and 1.1000, and you don't need to, nor can you, add trailing zeroes to a number for purposes of calculating.

When you want to "show" a number, or the result of a formula, you are presumably going to be doing that in a String meter. On that meter you can Use NumOfDecimals=4 and it will pad out the decimal places as needed with zeroes to be 4.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureCalc]
Measure=Calc
Formula=1 + 0.1

[MeterResult]
Meter=String
MeasureName=MeasureCalc
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=4
1.png
Maybe I need an example of what you mean.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Trailing Zeros

Post by balala »

jsmorley wrote: I don't really follow. There is no mathematical difference between 1.1 and 1.1000, and you don't need to, nor can you, add trailing zeroes to a number for purposes of calculating.

When you want to "show" a number, or the result of a formula, you are presumably going to be doing that in a String meter. On that meter you can Use NumOfDecimals=4 and it will pad out the decimal places as needed with zeroes to be 4.
1.png
Maybe I need an example of what you mean.
Reading the above posts, I think the problem is that Resike added the NumOfDecimals=4 option to the calc measure and that's why he couldn't make it to work. So, here important is to use that option onto the string meter.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Yes, that was sorta what I was getting at... The most likely reason to want to pad decimals places is to create a consistent number of characters for purposes of display, and you would pretty much always be using a String meter for that. NumOfDecimals only applies to a String meter.

Another remote possibility is that he wants to use the number in the context of a String meter where he doesn't want to pad decimal places on other numbers bound to the meter. In that case you can just use a [SectionVariable] with the :n "number of decimal places" parameter.

http://docs.rainmeter.net/manual/variables/section-variables#Decimals

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureCalc1]
Measure=Calc
Formula=37

[MeasureCalc2]
Measure=Calc
Formula=1 + 0.1

[MeterResult]
Meter=String
MeasureName=MeasureCalc1
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=%1 or [MeasureCalc2:4]
DynamicVariables=1
1.png
Using [SectionVariables] can give you as much control as you want over decimal places in a single String meter:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureCalc]
Measure=Calc
Formula=1

[MeterResult]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[MeasureCalc:0]#CRLF#[MeasureCalc:1]#CRLF#[MeasureCalc:2]#CRLF#[MeasureCalc:3]#CRLF#[MeasureCalc:4]
DynamicVariables=1
1.png
You do not have the required permissions to view the files attached to this post.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

I think this [SectionVariables] is what i need, i'm pretty new to the program, but i'll be soon ready with my currency exchange meter. Thanks for the help.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

And is it possible to change this value based on the strings length?

Lets say i would like to dynamically show strings like this:

1.0000
10.000
100.00
1000.0

And the string's value is coming from a WebParser plugin.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike wrote:And is it possible to change this value based on the strings length?

Lets say i would like to dynamically show strings like this:

1.0000
10.000
100.00
1000.0

And the string's value is coming from a WebParser plugin.
Don't follow that at all.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Trailing Zeros

Post by balala »

Resike wrote:And is it possible to change this value based on the strings length?

Lets say i would like to dynamically show strings like this:

1.0000
10.000
100.00
1000.0

And the string's value is coming from a WebParser plugin.
I don't know where you want to get that number, so to see how it's working I used a calc measure, but instead of it, you can use a WebParser measure:

Code: Select all

[Variables]
Num=12740

[MeasureNum]
Measure=Calc
Formula=#Num#
IfCondition=(MeasureNum<10)
IfTrueAction=[!SetOption MeterNum NumOfDecimals "4"]
IfCondition2=((MeasureNum>=10)&&(MeasureNum<100))
IfTrueAction2=[!SetOption MeterNum NumOfDecimals "3"]
IfCondition3=((MeasureNum>=100)&&(MeasureNum<1000))
IfTrueAction3=[!SetOption MeterNum NumOfDecimals "2"]
IfCondition4=((MeasureNum>=1000)&&(MeasureNum<10000))
IfTrueAction4=[!SetOption MeterNum NumOfDecimals "1"]
IfCondition5=(MeasureNum>=10000)
IfTrueAction5=[!SetOption MeterNum NumOfDecimals "0"]

[MeterNum]
Meter=String
MeasureName=MeasureNum
X=0
Y=0
FontSize=10
Padding=15,5,15,5
FontColor=255,255,255
solidColor=0,0,0,150
StringAlign=LEFT
AntiAlias=1
Text=%1
Add the IfCondition/IfTrueAction options to that WebParser measure which returns the number (changing the measure name on the IfConditions).