How can i output an answer when making an app so that it has a set number of decimal places.

1 view (last 30 days)
Hi,
I'm making an app and i need the answer to be a set number of decimal places so for example:
0.07 needs to be shown as 0.070
1 needs to be shown as 1.000
How can i do this in the app creator when outputting a variable to a label text using this code:
app.Label.Text = string(Tol);
Thanks

Answers (1)

Stephen23
Stephen23 on 2 Feb 2021
sprintf('%.3f',0.07)
ans = '0.070'
sprintf('%.3f',1)
ans = '1.000'

Products

Community Treasure Hunt

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

Start Hunting!