March 13, 2023, 9:53pm
I need to convert an Item with a UoM to a String without UoM.
Here is the Item:
Number:Intensity WC_PWS_Current_Radiation "Solar Radiation [%.1f %unit%]"
And here is the rule:
The script is expecting a number with just digits but toString() is converting the UoM too.
How can I remove the UoM?
(WC_PWS_Current_Radiation.state as Number).toString()
but I am still getting the number with it’s unit of measure. [=10 W/m²]
Can someone helps me to find the correct function to convert a number to a string without it’s UoM?
thanks a lot.
March 13, 2023, 10:00pm
You have to convert the state from a QuantityType to a DecimalType or a Number. It might be as easy as
or you may need to cast it
(WC_PWS_Current_Radiation.state as QuantityType<?>).intValue
or if that doesn’t work I think this will
(WC_PWS_Current_Radiation.state as Number).intValue
In JS Scripting with the 4.0 version of the helper library you can use
March 14, 2023, 12:51pm
executeCommandLine should convert the primitives to strings for you so there should be no need to call
toString(). Furthermore, the
intValue is a primitive which doesn’t have a
toString() method. So to convert that to a String you’d use either
March 14, 2023, 7:44pm
Hi, thanks for your reply.
This didn’t work to me.
It raises an error.
March 14, 2023, 7:49pm
I forgot the
new, as in