kasemir / org.csstudio.display.builder

Update of org.csstudio.opibuilder.*
Eclipse Public License 1.0
2 stars 10 forks source link

PVUtil.getString() rounds floating point numbers #413

Closed claudio-rosati closed 6 years ago

claudio-rosati commented 6 years ago

I'm not sure if it is a bug or if an alternative way of solving the original problem exists.

Asking for a PV's value in a JS script with PVUtil.getString() rounds the result. So for example 9.2e-2 will be 0. It should return the value with rounding.

See: CSSTUDIO-752.bob.zip

After few trial-and-errors, I suggested my integrator to use PVUtil.getDouble() instead. And this was the answer:

Yes, but getString() appends the engineering unit too. I also need that one. I am using the returned value to display the pressure as a tooltip on a gauge widget.

Looking at the PVUtil, I'm thinking that maybe we could:

claudio-rosati commented 6 years ago

Another comment from the integrator:

Actually what the operators really need is the number in exponential format. So it would be really useful to be able to specify the same format parameters as in the Format property of Text Update...

That would be a 4th option in my previous list.

kasemir commented 6 years ago

If you want that type of fine control, why not format it the way you want in the script? The PVUtil contains the basic getDouble(), getString() that has been helpful for the last 10 years of BOY usage, but nothing keeps you from calling the FormatOptionHandler:

from org.csstudio.display.builder.runtime.script import PVUtil
from org.csstudio.display.builder.model.properties import FormatOption
from org.csstudio.display.builder.model.util import FormatOptionHandler

vtype = PVUtil.getVType(pvs[0])
# Exponential, 5 digits, with units
text = FormatOptionHandler.format(vtype, FormatOption.EXPONENTIAL, 5, true)

Or get the number and format it any way you want in your own code.

Still, if you want to show a number with exponential notation, why not simply use a TextUpdate widget, enter the PV name, select the format? If the precision is wrong, fix that on the IOC. If you can't, OK, then enter the precision on the widget.

Why use a script at all?

claudio-rosati commented 6 years ago

I think that your example should be ok. I supposed only PVUtil was available inside the script. Anyway I’ll report all above to the integrator. Thank you