Inline JS transformation in sitemap not working

I have the following line in my sitemap:

Default item=Units label="Units [JS(|parseFloat(input)):%.1f U]"

The item is a string object and I want to convert it to a number and print only the first decimal on the UI. I am trying to perform the conversion using the inlinen JS transformation.

However the transformation does not seem to work and I get an error in the log:

2025-02-14 16:05:19.527 [WARN ] [ui.internal.items.ItemUIRegistryImpl] - Exception while formatting value '0.0' of item Units with format 'JS(|parseFloat(input)):%.1f U': f != java.lang.String

What am I doing wrong? Is someone able to help? Thanks

The problem is that a JS transform always returns a String. Therefore, you need to use %s instead of %.1f in the label and any rounding to one decimal place will need to also be handled in the JS.

[JS(|parseFloat(input).toFixed(1)):%s U]
1 Like

I would never have guessed that. I have been trying for hours to make this work. But I somehow knew that the solution would be simple :slightly_smiling_face:

Thanks a lot