Skip to content

add precision to handle floating or double number using getString function in scripts - #3999

Open
agaget wants to merge 1 commit into
ControlSystemStudio:masterfrom
agaget:precision
Open

agaget wants to merge 1 commit into
ControlSystemStudio:masterfrom
agaget:precision

Conversation

@agaget

@agaget agaget commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

In ValueUtil the precision is set to 0, that prevents floating or double number to display the number after the decimal point

So if for example we use the script provided in the example of phoebus for table

# Embedded python script
from org.csstudio.display.builder.runtime.script import PVUtil

# Create matrix (2D array) of strings
data = []

for pv in pvs:
    row =  [ pv.getName(), PVUtil.getString(pv) ]
    data.append(row)

widget.setValue(data)
image

After correction it is displayed correctly.
prec to 2
image
prec to 1
image

The advantage of using getString instead of getDouble is that it is displaying also the egu field

@sonarqubecloud

Copy link
Copy Markdown

@shroffk
shroffk self-requested a review November 2, 2026 15:30
@shroffk

shroffk commented Nov 2, 2026

Copy link
Copy Markdown
Member

Can you add some unit tests for this, you can use the examples you gave

@agaget

agaget commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

I can try but I'm not comfortable with JUnit and the already implemented test.

What do you expect exactly ? something like that : https://github.com/ControlSystemStudio/phoebus/blob/master/app/display/runtime/src/test/java/org/csstudio/display/builder/runtime/test/RulesJythonScriptTest.java

but for ValueUtil.getString ? ValueUtilJythonScriptTest.java or integrated in an already existing file ?

@shroffk

shroffk commented Nov 2, 2026

Copy link
Copy Markdown
Member

No worries... I can add them

I will merge this next Thursday after the developers meeting. Changes to the Util classes which are heavily used in scripting ( where things tend to be quite brittle ) can have wider impacts since we don't know all the various use cases.

But... In general I think this is an improvement so we should be merging this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants