Try not scaling the number (the "/1" part). I think all you need is Text=[MeasureString:1].
It is currently April 19th, 2024, 4:43 pm
How can I convert a string to a number?
-
- Rainmeter Sage
- Posts: 2603
- Joined: March 23rd, 2015, 5:26 pm
Re: How can I convert a string to a number?
-
- Posts: 5
- Joined: June 7th, 2021, 8:35 pm
Re: How can I convert a string to a number?
I just tried what you suggest (Text=[MeasureString:1]), but i get the same result (1.0 is displayed, instead of 1234.5)
-
- Rainmeter Sage
- Posts: 1399
- Joined: April 24th, 2021, 8:13 pm
Re: How can I convert a string to a number?
You got to convert the string from the string measure to a number before rounding it, because as JSMorley pointed out here, the default number value of a string measure is 1 if it's not a number(which is the case here cause of the "," in your number).
Code: Select all
[MeasureString]
Measure=String
String=1,234.5678
UpdateDivider=-1
Substitute=",":""
[MeasureNum]
Measure=Calc
Formula=[MeasureString]
UpdateDivider=-1
[MeterText]
Meter=String
X=10
Y=10
Text=[MeasureNum:1]
FontFace=Cascadia Code
AntiAlias=1
FontColor=FFFFFF
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
-
- Rainmeter Sage
- Posts: 7125
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: How can I convert a string to a number?
In addition to death.crafter's solution, you could avoid creating a new measure for that and just add OnUpdateAction=[!SetVariable MyNumber (Round([MeasureString],1))] to your [MeasureString], followed by displaying the new variable instead, in [Index], like Text=#MyNumber#.
Reference here.
-
- Posts: 5
- Joined: June 7th, 2021, 8:35 pm
Re: How can I convert a string to a number?
thx again for your quick answers !
Your solution death.crafter works indeed for my simplified problem thx !! (1234.5 is displayed)
However, when applied to my reel widget (Markets Prices by Mordasius), where the string is not defined as a String, but instead as a WebParser, it doesn't work anymore (0.0 is displayed, instead of 36758.7) :
Would you have more clue about this slightly different problem ?
Your solution death.crafter works indeed for my simplified problem thx !! (1234.5 is displayed)
However, when applied to my reel widget (Markets Prices by Mordasius), where the string is not defined as a String, but instead as a WebParser, it doesn't work anymore (0.0 is displayed, instead of 36758.7) :
Code: Select all
[InfoIndex4]
Measure=WebParser
URL=https://www.cnbc.com/quotes/#Symbol4#
UserAgent=#MyUserAgent#
Header=Accept: text/html
Header2=Accept_Encoding: gzip, deflate, br
Header3=Accept_Language: en-US
Header4=Connection: close
Header5=Dnt: 1
Header6=Host: www.CNBC.com
Header7=Referer: https://wwww.google.com
RegExp=#ExpQuote#
StringIndex=1
UpdateRate=#UpdateQuotes#
[mIndex4_Price]
Measure=WebParser
Url=[InfoIndex4]
StringIndex=2
Substitute=",":""
[mIndex4_PriceNum]
Measure=Calc
Formula=[mIndex4_Price]
UpdateDivider=-1
[LabelIndex4_Price]
Meter=STRING
X=10
Y=10
Text=[mIndex4_PriceNum:1]
DynamicVariables=1
-
- Rainmeter Sage
- Posts: 7125
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: How can I convert a string to a number?
Remove UpdateDivider=-1 and add DynamicVariables=1 to [mIndex4_PriceNum] and it will work. The former allows the measure to update more than once at skin refresh (when the WebParser still didn't get its data from the site), and the latter allows the measure to "see" the dynamic (since it was changed by the substitution and its parent WebParser) value of the [mIndex4_Price] section variable: (I used the 3rd price here, since the 4th was less than 1000; I also used Mordasius' meter instead of creating another one, since it had the style and all already set)
You do not have the required permissions to view the files attached to this post.
-
- Posts: 5
- Joined: June 7th, 2021, 8:35 pm
Re: How can I convert a string to a number?
Your solutions combined work perfectly !
Really thank you a lot death.crafter and Yincognito !
Really thank you a lot death.crafter and Yincognito !
-
- Rainmeter Sage
- Posts: 7125
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita