Convert an Item with a UoM in a String without UoM

Hi all,
I need to convert an Item with a UoM to a String without UoM.
Item=10 W/m²
Desired String=“10”

Here is the Item:
Number:Intensity WC_PWS_Current_Radiation "Solar Radiation [%.1f %unit%]"

And here is the rule:
executeCommandLine("/usr/bin/python3.7","/srv/openhab-conf/scripts/e2.py","2023",now().format(DateTimeFormatter.ofPattern("MM")),WC_PWS_Current_Radiation.state.toString())

The script is expecting a number with just digits but toString() is converting the UoM too.
How can I remove the UoM?

I tried:
(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.

You have to convert the state from a QuantityType to a DecimalType or a Number. It might be as easy as

WC_PWS_Current_Radiation.state.intValue

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

items[WC_PWS_Current_Radiation].numericState

Hi,
You mean:

WC_PWS_Current_Radiation.state.intValue.toString()

or

(WC_PWS_Current_Radiation.state as Number).intValue.toString()

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

''+WC_PWS_Current_Radiation.state.intValue

or

String(WC_PWS_Current_Radiation.state.intValue)

Hi, thanks for your reply.

This didn’t work to me.
It raises an error.

I forgot the new, as in new String(....