It is currently April 19th, 2024, 11:07 pm

How can I convert a string to a number?

Get help with creating, editing & fixing problems with skins
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

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

Post by jav26122 »

Still can't get this to work... Once I figure out how to do this for one I can do the rest but it's not working.

It just says "GPU: MHz"

Code: Select all

[Rainmeter]
Background=..\Images\bg_ram_cpu.png
Update=1000

[Variables]
@Include=#@#\HWiNFO.inc
@Include2=..\UserVariables.inc

[MeasureGPUMHz]
Meter=Plugin
Plugin=HWiNFO.dll
HWiNFOSensorId=#HWiNFO-GPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-GPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-GPU0-CoreClock#
HWiNFOType=CurrentValue


[GPUMHz]
Meter=STRING
MeasureName=MeasureGPUMHz
X=95
Y=47
FontColor=#FontColor1#
FontSize=7
FontFace=#FontFace#
StringStyle=BOLD
StringAlign=left
Prefix="GPU: "
PostFix=" MHz"
AntiAlias=1
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

jav26122 wrote:Still can't get this to work... Once I figure out how to do this for one I can do the rest but it's not working.

It just says "GPU: MHz"

Code: Select all

[Rainmeter]
Background=..\Images\bg_ram_cpu.png
Update=1000

[Variables]
@Include=#@#\HWiNFO.inc
@Include2=..\UserVariables.inc

[MeasureGPUMHz]
Meter=Plugin
Plugin=HWiNFO.dll
HWiNFOSensorId=#HWiNFO-GPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-GPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-GPU0-CoreClock#
HWiNFOType=CurrentValue


[GPUMHz]
Meter=STRING
MeasureName=MeasureGPUMHz
X=95
Y=47
FontColor=#FontColor1#
FontSize=7
FontFace=#FontFace#
StringStyle=BOLD
StringAlign=left
Prefix="GPU: "
PostFix=" MHz"
AntiAlias=1
The first thing you are going to want to know is if the plugin measure is really working and returning a value. The "About / Skins" dialog from the Rainmeter context menu can help you there.
1.jpg
You might also want to check "About / Log" to see if there are any error messages.

Then, although it isn't important to the functionality, don't use Prefix and Postfix. They are prehensile tails that you almost never need.

Code: Select all

[GPUMHz]
Meter=STRING
MeasureName=MeasureGPUMHz
X=95
Y=47
FontColor=#FontColor1#
FontSize=7
FontFace=#FontFace#
StringStyle=BOLD
StringAlign=left
Text=GPU: %1 MHz
AntiAlias=1
The %1 is a placeholder for the value that is returned in MeasureName on the meter.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

I see the issue.

[MeasureGPUMHz]
Meter=Plugin

a Plugin is not a "meter", but a "measure".

[MeasureGPUMHz]
Measure=Plugin
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

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

Post by jav26122 »

jav26122 wrote:Still can't get this to work... Once I figure out how to do this for one I can do the rest but it's not working.

It just says "GPU: MHz"

Code: Select all

[Rainmeter]
Background=..\Images\bg_ram_cpu.png
Update=1000

[Variables]
@Include=#@#\HWiNFO.inc
@Include2=..\UserVariables.inc

[MeasureGPUMHz]
Meter=Plugin
Plugin=HWiNFO.dll
HWiNFOSensorId=#HWiNFO-GPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-GPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-GPU0-CoreClock#
HWiNFOType=CurrentValue


[GPUMHz]
Meter=STRING
MeasureName=MeasureGPUMHz
X=95
Y=47
FontColor=#FontColor1#
FontSize=7
FontFace=#FontFace#
StringStyle=BOLD
StringAlign=left
Prefix="GPU: "
PostFix=" MHz"
AntiAlias=1
omfg how did I not see that it was Meter=Plugin instead of Measure=Plugin....
k it's working fine now
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

Excellent...

I really like HWiNFO. Takes a minute to wrap your head around all those values you have to set from SharedMemoryViewer.exe, but once you do, it is very powerful, lightweight and returns oodles of stuff.

I use it all the time.
1.jpg
2.jpg
You do not have the required permissions to view the files attached to this post.
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

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

Post by jav26122 »

Thanks for all the help. Thought you might want to see it since you've helped me with this so much.
http://imgur.com/a/5ZfVE

Image

Image

Image

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

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

Post by jsmorley »

Looks good. Nice work.
yamato
Posts: 5
Joined: June 7th, 2021, 8:35 pm

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

Post by yamato »

Hi all
Newby here
I need to use a string as a number,
however it doesn't work, because the format of the string is such as : 1,234.5 (with a coma)
I already tried :

Code: Select all

Substitute:",":""
that works well to get rid of the coma, but the result (1234.5) oddly doesn't seems to be usable as a number, or when I use it as a number, that number is 1 (not 1234.5).
What's going wrong ?
yamato
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

yamato wrote: June 7th, 2021, 8:41 pm Hi all
Newby here
I need to use a string as a number,
however it doesn't work, because the format of the string is such as : 1,234.5 (with a coma)
I already tried :

Code: Select all

Substitute:",":""
that works well to get rid of the coma, but the result (1234.5) oddly doesn't seems to be usable as a number, or when I use it as a number, that number is 1 (not 1234.5).
What's going wrong ?
yamato
The key is that you must use the "string" value of the measure containing the numeric value, so the Substitute is applied where the value is used. Substitute is only applied to the string value of a measure, and only at the time and place where the string value is "used".

Code: Select all

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

[Variables]
MyNum=1,234.5

[MeasureString]
Measure=String
String=#MyNum#
Substitute=",":""

[MeasureNumber]
Measure=Calc
Formula=([MeasureString] + 765.5)
DynamicVariables=1

[MeterNumber]
Meter=String
MeasureName=MeasureNumber
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
NumOfDecimals=1
AntiAlias=1
The important bit here is that I am using the [MeasureString] section variable to get the value. That will force the Calc measure to use the string value of the measure, and it will then convert it to a number if the result is in fact numeric. Note that if I just used Formula=MeasureString + 765.5, that would attempt to use the number value of the measure, without any Substitute applied, and the value would be "1", which is where it will stop trying to convert it to a number, since a , comma is not a valid part of a numeric value. So the answer would be 766.5, which is the 1 added to the 765.5

https://docs.rainmeter.net/manual/variables/section-variables/#MeasureParameters


1.jpg
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?

Post by yamato »

Thx for help !

To focus more on my problem, here is an example :

First, I write this :

Code: Select all

[Rainmeter]
MiddleMouseUpAction=!Refresh
AccurateText=1

[Variables]
MyNum=1,234.5678

[MeasureString]
Measure=String
String=#MyNum#
Substitute=",":""

[Title]
Meter=STRING
FontColor=cccccc
X=36
Y=5
Text=Refresh
UpdateDivider=-1

[Index]
Meter=STRING
FontColor=cccccc
X=130
Y=32
Text=[MeasureString]
DynamicVariables=1
... and this woks as expected (1234.5678 is displayed)

Then I try this, in order to round the number :

Code: Select all

[Index]
Meter=STRING
FontColor=cccccc
X=130
Y=32
Text=[MeasureString:/1,1]
DynamicVariables=1
... and this works not as expected (1.0 is displayed, instead of 1234.5)

Have you a clue about this ?