It is currently November 29th, 2021, 6:18 am

Decimal...

Help with creating, editing & fixing problems with skins
maxmax00
Posts: 3
Joined: April 24th, 2010, 8:12 pm

Decimal...

Post by maxmax00 »

Hi, my input from WebParser.dll it could be for exsample: 6,88 or 5,746

I need to calculate a formula with this numbers... Comma is the first problem, I cant do formulas with that strings because it will cut the decimal. (I have tried with Substitute=",":"." but didnt work)

so i turn my RegExp line in something like this: RegExp="<***********>(.*),(.*)<****>" but even in this case i cant do Formula=Measure2/1000+Measure1
because :

case 1: 5,746 = 5.746 OK
case 2: 6,88 = 6.088 WRONG


what can i do?

ps: sorry for my english
User avatar
jsmorley
Developer
Posts: 22414
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Decimal...

Post by jsmorley »

I really think it is looking for the UK / US method for the decimal places and thousands grouping indicators.

1,200 = One Thousand Two Hundred
12.89 = Twelve point Eight Nine

If I have a text file:

test.txt

And in it put
<1>123.98</1>

Then:

[MeasureLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#test.txt
RegExp="(?siU)<1>(.*)</1>"
StringIndex=1

[MeasureDivide]
Measure=Calc
Formula=(MeasureLink / 100)

[MeterNumber]
Meter=String
MeasureName=MeasureLink
MeasureName2=MeasureDivide
NumOfDecimals=4
FontSize=20
FontColor=255,255,255,255
Text = %1 | %2

Works fine, and displays 123.98 | 1.2398

If however, I have in test.txt:

<1>123,98</1>

Then the same .ini code above returns 123,98 | 1.2300

Which is just 123 / 100 as it is ignoring everything after the comma, which it just doesn't understand to be a decimal place indicator.

Not sure what the right answer is here. Maybe Kenz0 or Alex can jump in. Putting a Substitute=",":"." on the WebParser measure doesn't help, as substitutions are purely cosmetic and are not done when you use the result in a "Calc". However there must be come clever way to get around this limitation that Calc doesn't seem to like "," as decimals and "." as thousands separators, which is standard in many countries outside of the US and UK.
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Decimal...

Post by Alex2539 »

The substitute will work, but you need to change how you use the measure in the formula. Instead of using just the measure name, encase it in square brackets and then add the line DynamicVariables=1. This way, the substitute will go through, replacing the "," with a "." like so:

Code: Select all

[ExampleCalc]
Measure=Calc
Formula=[SomeMeasure]
DynamicVariables=1
ImageImageImageImage
User avatar
jsmorley
Developer
Posts: 22414
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Decimal...

Post by jsmorley »

Thanks Alex. I completely forgot about that.

A fuller explanation is here: http://rainmeter.net/cms/Tips-SubValuesInCalc
maxmax00
Posts: 3
Joined: April 24th, 2010, 8:12 pm

Re: Decimal...

Post by maxmax00 »

Code: Select all

[MeasureLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#test.txt
RegExp="(?siU)<1>(.*)</1>"
StringIndex=1

[MeasureDivide]
Measure=Calc
Formula=(MeasureLink / 100)
DynamicVariables=1

[MeterNumber]
Meter=String
MeasureName=MeasureLink
MeasureName2=MeasureDivide
MeasureName3=GetSubstitutedValue
NumOfDecimals=4
FontSize=10
FontColor=255,255,255,255
Text = %1 | %2 | %3 

[InitialValue] 
Measure=Calc 
Formula=MeasureLink

[GetSubstitutedValue] 
Measure=Calc 
Formula=[InitialValue]/100
DynamicVariables=1
the output still the same... :(

12,34 | 0.01200 | 0.01200
User avatar
jsmorley
Developer
Posts: 22414
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Decimal...

Post by jsmorley »

Code: Select all

[MeasureLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#test.txt
RegExp="(?siU)<1>(.*)</1>"
Substitute=",":"."
StringIndex=1

[MeasureDivide]
Measure=Calc
Formula=([MeasureLink] / 100)
DynamicVariables=1

[MeterNumber]
Meter=String
MeasureName=MeasureLink
MeasureName2=MeasureDivide
NumOfDecimals=4
FontSize=10
FontColor=255,255,255,255
Text = %1 | %2
You still need the substitution, you didn't have one in your version of my code. So you do the substitution on the WebParser measure as you would if you were just displaying the results, then use the value returned in square brackets [MeasureLink] in a calc with DynamicVariables=1 and it will get the 123.98 in the calc instead of 123,98. Now you can use THAT value any way you want.

123.98 | 1.2398
maxmax00
Posts: 3
Joined: April 24th, 2010, 8:12 pm

Re: Decimal...

Post by maxmax00 »

lol right i forgot the Substitute :facepalm:

thank you soo much ^_^
User avatar
jsmorley
Developer
Posts: 22414
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Decimal...

Post by jsmorley »

No problem. By the way, if you want to "calculate" using the period (which you must) but still "display" the original value with the comma, do it like this:

Code: Select all

[MeasureLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#test.txt
RegExp="(?siU)<1>(.*)</1>"
StringIndex=1

[MeasureLinkSubstituted]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureLink]
Substitute=",":"."
StringIndex=1

[MeasureDivide]
Measure=Calc
Formula=([MeasureLinkSubstituted] / 100)
DynamicVariables=1

[MeterNumber]
Meter=String
MeasureName=MeasureLink
MeasureName2=MeasureLinkSubstituted
MeasureName3=MeasureDivide
NumOfDecimals=4
FontSize=10
FontColor=255,255,255,255
Text = %1 | %2 | %3
123,98 | 123.98 | 1.2398