Quickest way to strip 3 characters off a String item and convert to a Number

I am using the SNMP binding to query my QNAP NAN and return things such as fan speeds, temps and HD status.

I also have it returning total disk space and free disk space. However these are returned as something like “2.67 TB” and so up till now I have just put them into a String item in OpenHAB.

Now I’d like to use both values to work out a free space % so I need to store them to numbers… Is this something I could do using a script as part of the item config or should I be doing it in a rule? Ideally I’d like to not have to store it as text just to then convert it to a number, if I could strip off the " TB" as it comes in then that would be fantastic.

Any ideas would be appreciated!

String QNAP_HDSize “Scarlet HD Total [%s]” (ScarletServer) {snmp="<[192.168.1.xxx:topsecretphrase:.1.3.6.1.4.1.24681.1.2.17.1.4.1:300000]"}

It doesn’t look like the SNMP binding supports transforms so you will have to use a rule. Only bindings that support transforms let you create mappings, regular expressions, JavaScript functions, etc to muck with the values before they get sent to the Item.