Shorten values, reformat

Hi there, I’ve a problem when use UoM Values from some Channels. For Example the DarkSky WindSpeed is defined as Channel:
darksky:weather-and-forecast:XXXXXX:local:current#wind-speed Number:Speed
The Value may now 22.21196446084264454925689549645575 km/h and is shown in Paper UI as 22.2 km/h.
When using this Channel in Rules in a StringBuilder like this
val StringBuilder msg1 = new StringBuilder msg1.append(darksky_weather_and_forecast_XXXXXX_local_current_wind_speed.state)
the full value is appended to msg1. Formating the Channel.State with ("%.1f") drops the Unit.
Alternativly I may use this formating Channel.State with ("%.1f %unit%"), but I have to change all used channels.
Maybe there is an ‘precision’ vaule available which can be set to format the Channel result.

Are you looking for something like this?

msg = String::format("%.1f", (Weather_currentTemperature.state as DecimalType).floatValue()) +"°C"

The object you are using in rules with your stringbuilder is an Item, not a channel. It’ll really help you in future to understand these parts. Channels provide the links between Items and Things.

I think you should be able to use -

val String test = darksky_weather_and_forecast_XXXXXX_local_current_wind_speed.state.format("%.1f %unit%")

But if not … this isn’t very elegant, but I think works around StringBuilder that you have chosen to use not knowing anything about QuantityTypes?

// get raw number
val Number internum = (darksky_weather_and_forecast_XXXXXX_local_current_wind_speed as QuantityType<Number>).floatValue
// now format and add units
val String test = String::format("%.1f km/h", internum)