It is currently June 16th, 2021, 11:35 am

## How can I convert a string to a number?

Help with creating, editing & fixing problems with skins
SilverAzide
Rainmeter Sage
Posts: 1290
Joined: March 23rd, 2015, 5:26 pm

### Re: How can I convert a string to a number?

yamato wrote: June 8th, 2021, 6:56 pm ... and this works not as expected (1.0 is displayed, instead of 1234.5)
Try not scaling the number (the "/1" part). I think all you need is Text=[MeasureString:1].
yamato
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)
death.crafter
Posts: 176
Joined: April 24th, 2021, 8:13 pm

### Re: How can I convert a string to a number?

yamato wrote: June 9th, 2021, 5:24 am I just tried what you suggest (Text=[MeasureString:1]), but i get the same result (1.0 is displayed, instead of 1234.5)
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]
AntiAlias=1
FontColor=FFFFFF
DynamicVariables=1
``````
Image:
Screenshot 2021-06-09 130940.png
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

### Re: How can I convert a string to a number?

yamato wrote: June 9th, 2021, 5:24 am I just tried what you suggest (Text=[MeasureString:1]), but i get the same result (1.0 is displayed, instead of 1234.5)
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.
yamato
Posts: 5
Joined: June 7th, 2021, 8:35 pm

### Re: How can I convert a string to a number?

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#
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
``````
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

### Re: How can I convert a string to a number?

yamato wrote: June 10th, 2021, 6:42 pmHowever, 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)
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:
Result.jpg
(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.
yamato
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 !
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita