If you want to have absolute control over the display format for the "third EditField", then you may consider changing the type from NumericEditField
to EditField
, i.e. the string version. Then you can format the number as a string and display as you want, e.g. with units or comma separators.
Using your example:
"Instead of 1.0e+4 I [want] 10,000".
Having an app in appdesigner
with the following graphics objects:
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
LabelNumber1 matlab.ui.control.Label
Number1 matlab.ui.control.NumericEditField
LabelNumber2 matlab.ui.control.Label
Number2 matlab.ui.control.NumericEditField
ResultEditFieldLabel matlab.ui.control.Label
Result matlab.ui.control.EditField
Calculate matlab.ui.control.Button
end
Notice the Result
object is a standard string-based EditFIeld
, your button callback function could be:
% Button pushed function: Calculate
function doCalculation(app, event)
value_1 = app.Number1.Value;
value_2 = app.Number2.Value;
% Calculation
result = value_1 + value_2;
resultFormatted = num2str(result);
app.Result.Value = resultFormatted;
end
But to get the formatting like you ask, i.e. 10,000, you'll need to format the resultFormatted
string accordingly. Now, having the result EditField as a string, any formatting changes you make will be preserved, such as the comma separator. It also allows the flexibility to avoid having decimals show when there are none (10000
=> '%.2f'
=> '10000.00'
), or unwanted rounding (56.576
=> '%.2f'
=> '56.58'
).
Getting the comma-separator in the formatting is not explicitly part of your question, but there are many ways to do that. I'm happy to share my solution should anyone want it.
Best Regards.