It is currently December 6th, 2022, 1:44 pm

## Text meter: Limit number of digits displayed with IfCondition >10

Get help with creating, editing & fixing problems with skins
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

### Text meter: Limit number of digits displayed with IfCondition >10

Dear team, I have one more stupid question, have tried to find solutions in the rainmeter documentation and via google but no sucesss.

Problem description:
- See screenshot, I have added a meter displaying a number with one decimal - in this case it's "1.6", marked with yellow arrow
- All numbers are coming from a webparser measure and in this case the number can be greater than 10, e.g. 12.3
- In this case it collides with the arrow meter left of the number...
- See below my meter code: MeasureIOB after parsing is actualy a number with 2 decimals, in this case it was 1.63

What I want:
1) In case MeasureIOB <10 -> no changes, display with 1 decimal is perfectly fine
2) In case MeasureIOB >=10 -> it should only display the first two digits and no decimal, then it will fit!

Example: e.g. MeasureIOB = 12.32 -> then, the meter should only display "12" thus no decimals like with [&MeasureIOB:0]

Any ideas how this can be done? How can I add such an IfCondition to the meter? Many thanks for your guidance!!

Code: Select all

``````[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureIOB
X=136
Y=26
W=40
H=21
Text=[&MeasureIOB:1]
DynamicVariables=1``````
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

### Re: Text meter: Limit number of digits displayed with IfCondition >10

emp00 wrote: November 6th, 2022, 8:53 pm Dear team, I have one more stupid question, have tried to find solutions in the rainmeter documentation and via google but no sucesss.

Problem description:
- See screenshot, I have added a meter displaying a number with one decimal - in this case it's "1.6", marked with yellow arrow
- All numbers are coming from a webparser measure and in this case the number can be greater than 10, e.g. 12.3
- In this case it collides with the arrow meter left of the number...
- See below my meter code: MeasureIOB after parsing is actualy a number with 2 decimals, in this case it was 1.63

What I want:
1) In case MeasureIOB <10 -> no changes, display with 1 decimal is perfectly fine
2) In case MeasureIOB >=10 -> it should only display the first two digits and no decimal, then it will fit!

Example: e.g. MeasureIOB = 12.32 -> then, the meter should only display "12" thus no decimals like with [&MeasureIOB:0]

Any ideas how this can be done? How can I add such an IfCondition to the meter? Many thanks for your guidance!!

Code: Select all

``````[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureIOB
X=136
Y=26
W=40
H=21
Text=[&MeasureIOB:1]
DynamicVariables=1``````
Since you haven't shared my required part of the code I don't know which measure the condition will interfere with.
However I think the code will be like below.

Code: Select all

``````[CalcNumDec]
Measure=Calc
Formula=MeasureIOB
IfCondition= CalcNumDec > 10
IfTrueAction= [!SetOption MeasureIOB NumOfDecimals "0"]
IfFalseAction= [!SetOption MeasureIOB NumOfDecimals "2"]
``````
I don't know where i going from here, but i promise it won't be boring...
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

### Re: Text meter: Limit number of digits displayed with IfCondition >10

tass_co wrote: November 6th, 2022, 9:52 pm Since you haven't shared my required part of the code I don't know which measure the condition will interfere with.
However I think the code will be like below.
The measure code is as simple as follows, see below ... It's the substring from a Webparser RegExp ... As mentioned above, MeasureIOB returns already a number, e.g. "12.3" oder "3.5" ... I think adding the IfCondition to this meter does not work, right?

Code: Select all

``````[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7``````
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

### Re: Text meter: Limit number of digits displayed with IfCondition >10

emp00 wrote: November 6th, 2022, 9:58 pm The measure code is as simple as follows, see below ... It's the substring from a Webparser RegExp ... As mentioned above, MeasureIOB returns already a number, e.g. "12.3" oder "3.5" ... I think adding the IfCondition to this meter does not work, right?

Code: Select all

``````[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7``````
Sorry, im not sure.
I don't know where i going from here, but i promise it won't be boring...
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

### Re: Text meter: Limit number of digits displayed with IfCondition >10

tass_co wrote: November 6th, 2022, 10:19 pm Sorry, im not sure.
I tried your suggestion (see code below) but it does not work. See screenshot, in this case [MeasureCOB] = 7.99 but your "NumOfDecimals" code does not have the desired effect. I used NumOfDecimals "1" and the IfCondition should be False in this case (7.99 is <10) ...

Code: Select all

``````[MeasureCOB]
; COB = Carbs on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=8
IfCondition=MeasureCOB >= 10
IfTrueAction=[!SetOption MeasureIOB NumOfDecimals "0"]
IfFalseAction=[!SetOption MeasureIOB NumOfDecimals "1"]``````
Also using [!SetOption MeterIOB NumOfDecimals...] (instead of MeasureIOB) does not work...
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

### Re: Text meter: Limit number of digits displayed with IfCondition >10

emp00 wrote: November 6th, 2022, 10:28 pm I tried your suggestion (see code below) but it does not work. See screenshot, in this case [MeasureCOB] = 7.99 but your "NumOfDecimals" code does not have the desired effect.

Code: Select all

``````[MeasureCOB]
; COB = Carbs on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=8
IfCondition=MeasureCOB >= 10
IfTrueAction=[!SetOption MeasureIOB NumOfDecimals "0"]
IfFalseAction=[!SetOption MeasureIOB NumOfDecimals "1"]``````
Also using [!SetOption MeterIOB NumOfDecimals...] (instead of MeasureIOB) does not work...
I thing you need Substitute.

Code: Select all

``````RegExpSubstitute=1
Substitute=
IfCondition=MeasureCOB >= 10
IfTrueAction=[!SetOption MeasureIOB Substitute ""(.*\.\d{0})\d*":"\1""]
IfFalseAction=[!SetOption MeasureIOB Substitute ""]``````
I don't know where i going from here, but i promise it won't be boring...
xenium
Posts: 719
Joined: January 4th, 2018, 9:52 pm

### Re: Text meter: Limit number of digits displayed with IfCondition >10

emp00 wrote: November 6th, 2022, 8:53 pm Dear team, I have one more stupid question, have tried to find solutions in the rainmeter documentation and via google but no sucesss.

Problem description:
- See screenshot, I have added a meter displaying a number with one decimal - in this case it's "1.6", marked with yellow arrow
- All numbers are coming from a webparser measure and in this case the number can be greater than 10, e.g. 12.3
- In this case it collides with the arrow meter left of the number...
- See below my meter code: MeasureIOB after parsing is actualy a number with 2 decimals, in this case it was 1.63

What I want:
1) In case MeasureIOB <10 -> no changes, display with 1 decimal is perfectly fine
2) In case MeasureIOB >=10 -> it should only display the first two digits and no decimal, then it will fit!

Example: e.g. MeasureIOB = 12.32 -> then, the meter should only display "12" thus no decimals like with [&MeasureIOB:0]

Any ideas how this can be done? How can I add such an IfCondition to the meter? Many thanks for your guidance!!

Code: Select all

``````[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureIOB
X=136
Y=26
W=40
H=21
Text=[&MeasureIOB:1]
DynamicVariables=1``````
Try this:

Code: Select all

``````[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7

[MeasureSettingDecimals]
Measure=String
String=[MeasureIOB]
DynamicVariables=1
IfCondition=MeasureIOB < 10
IfTrueAction=[!SetOption MeterIOB Text "[MeasureIOB:1]"]
IfCondition2=MeasureIOB >= 10
IfTrueAction2=[!SetOption MeterIOB Text "[MeasureIOB:0]"]

[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
X=136
Y=26
W=40
H=21
DynamicVariables=1``````
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

### Re: Text meter: Limit number of digits displayed with IfCondition >10

xenium wrote: November 7th, 2022, 7:00 am Try this:

Code: Select all

``````[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7

[MeasureSettingDecimals]
Measure=String
String=[MeasureIOB]
DynamicVariables=1
IfCondition=MeasureIOB < 10
IfTrueAction=[!SetOption MeterIOB Text "[MeasureIOB:1]"]
IfCondition2=MeasureIOB >= 10
IfTrueAction2=[!SetOption MeterIOB Text "[MeasureIOB:0]"]

[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
X=136
Y=26
W=40
H=21
DynamicVariables=1``````
I tried both of your above suggestions - but all of them result in "0.0" as constant output of the meter. Obviously, the IfCondition -> SetOption bang somehow never fires... I can confirm 100% that both MeterIOB and MeasureSettingDecimals contain the correctly parsed number in the log/skins tab e.g. 3.95 is shown both for "Number" and "String" but the meter only displays "0.0". Why?

I'm out of luck, would be great if somebody had a working solution. Thanks guys!
balala
Rainmeter Sage
Posts: 14766
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Text meter: Limit number of digits displayed with IfCondition >10

emp00 wrote: November 6th, 2022, 10:28 pm I tried your suggestion (see code below) but it does not work. See screenshot, in this case [MeasureCOB] = 7.99 but your "NumOfDecimals" code does not have the desired effect. I used NumOfDecimals "1" and the IfCondition should be False in this case (7.99 is <10) ...
Try this. No need for the [MeasureCOB] measure I think:

Code: Select all

``````[MeasureIOB]
Measure=WebParser
URL=[MeasureSite]
StringIndex=7
IfCondition=([MeasureIOB]>=10)
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "0"]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "1"]
DynamicVariables=1``````
Don't forget to add the DynamicVariables=1 option as well, because you're using a section variable on the measure, which requires setting this option.
Note that the [!SetOption MeasureIOB NumOfDecimals "(Whatever)"] form of bangs used in the IfTrueAction and IfFalseAction options can't work, because the NumOfDecimals option belongs to String meters, not to any kind of measure. So, as you figured it out, replace the bangs with these: [!SetOption MeterIOB NumOfDecimals "X"] (this is what I used in the above posted code of the [MeasureIOB] measure).
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

### Re: Text meter: Limit number of digits displayed with IfCondition >10

I changed the [MeterIOB] as exactly as you proposed incl. DynamicVariables=1. However, now the number is displayed always with two digits: For example, currently my value is 0.17 and this is shown instead of the desired rounded 0.2 with one digit. It looks like both [!SetOption MeterIOB NumOfDecimals "X"] bangs don't work.

Are you sure the IfCondition is really executed in a WebParser measure like that? I have a feeling this is the reason...

On the other hand, can you have a closer look at the meter code below? I changed the "Text=" code to "%1" (previously I was using [&MeasureIOB:1]. As far as I understand %1 refers to the MeasureIOB number in this case. So if this meter fits to your MeterIOB code, then either the IfCondition does not execute or the NumOfDecimals does not have the desired effect. Scratching my head...
[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7
IfCondition=([MeasureIOB]>=10)
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "0"]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "1"]
DynamicVariables=1

[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureIOB
X=138
Y=26
W=40
H=21
; Adding ":1" ensures display of 1 decimal, also for X.0 otherwise giving X !
;Text=[&MeasureIOB:1]
Text="%1"
DynamicVariables=1