Appdesigner Numeric Edit Field value is displayed different when user tries to edit

When the value of a numeric field edited by a function (we can assume a basic divide pi/exp(1) as the value), it displays the value as the ValueDisplayFormat identifies (in my application, 4 digit fraction (%.4f) like 1.1557). However, when user tries to edit this value, numeric field shows around 15 digits, even the value is rounded to 4th digit which makes editing values by user very hard due to all this digits. Is there a better way to implement such a feature using a different data type maybe (because I think problem arises from double cannot exactly is roundable to fractions) to not change number of digits in the fraction when user tries to edit it?

Answers (1)

Hi,
Just use round function on the user input, Event.NewData IIRC.

5 Comments

You mean ValueChangedCallback?, The problem occurs while the user editing the field not before or after the field is edited, the value I'm setting the numeric field is already rounded before and after the user input or function changing the value of the edit field
Yes, sorry for not being clear. What is the issue exactly here? What happens during the user edit of the component?
In the ValueChangedCallback, user data will be in the Event.Value.
It's quite hard to put it in words but when user clicks on a edit field, application highlights that edit field. In exactly that highlighted state, due to the doubles cannot be roundable to exact fractions, instead rounded value of only 1.1557 it shows 1.15570000000000015 value
Make a minimal example and upload it so I can check it.
Sorry, my workflow is a little busy and I cannot had any time to make a basic example but I guess there is a different approach about round when it comes to the EditField.Value property. If I set a property to a value like app.result = round(pi/exp(1), 4) with result being a double, then set EditField.Value = app.result it shows a value like 1.15570000000000015 but if I set it like app.result =pi/exp(1) then EditField.Value = round(app.result, 4) then the field shows 1.1557. However, I didn't had time to throughly explore this behaviour and prove that is the reason.

Sign in to comment.

Categories

Products

Release

R2019a

Asked:

Tek
on 8 Sep 2023

Commented:

Tek
on 11 Oct 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!