Display number always with decimal places

I have a fader that goes from 0 to 10 in 0.5 increments.

The possible values are: 0.0,0.5,1.0,1.5,2.0,...,9.5,10.0

But it displays: 0,0.5,1,1.5,2,...,9.5,10 (whole numbers no decimal point)

I have tried in the value field: JS{{ return @{myfader}.toFixed(1) }}

But whole numbers are still showing without decimals, ie 0,1,2...

Any suggestions for force numbers like 1 to display as 1.0 ?

JavaScript thinks the whole numbers are integers, @JonnyTech, so you need to force them to floats before forcing decimal points on them.

parseFloat(n).toFixed(1) works in my browser console so something like JS{{ return parseFloat(@{myfader}).toFixed(1) }} ought to do it.

Thanks @erictheise, I should have stated that I already tried that, it logs the value correctly to the console but the display (I should have stated that I am using a text widget) displays an integer for whole numbers.

"value": "JS{{ console.log(parseFloat((@{myfader}).toFixed(1))); return (parseFloat(@{myfader}).toFixed(1)) }}"

Maybe this is a bug or limitation with O-S-C so I am including a minimal project (4.2 KB) to replicate the issue (pinging @jean-emmanuel in case).


On your text widget, @JonnyTech, try using:

@{myfader} for value:value and set(this, (parseFloat(get('myfader')).toFixed(1))) for scripting:onValue.

Works, may not be the most elegant way to do it.

Haha, great minds think alike! I came up with something very similar:


You are right, it does work, and it is not elegant! :rofl:

Thank you again @erictheise, I sincerely appreciate your efforts.

I shall keep this open in case it is an actual O-S-C bug though.