How to represent percentage values in Matlab App Designer

4 views (last 30 days)
Is there any easy way to represent percentage values in Matlab App Designer? For example, in excel we can type 8% and it will represent 0.08. I am making a basic calculator and have no idea how to get it to work.
Edit: this is what I have for the percentage button:
app.BResultado.Value=sprintf(‘%.0f%%’),app.BResultado.Value*100);
But when I press let’s say 7. Instead of 0.07 I get 5500%

Answers (1)

Voss
Voss on 2 Apr 2022
Consider the differences in the following commands:
val = '7'
val = '7'
sprintf('%.0f%%',val*100)
ans = '5500%'
sprintf('%.0f%%',str2double(val)*100)
ans = '700%'
sprintf('%.0f%%',str2double(val)/100)
ans = '0%'
sprintf('%0.2f%%',str2double(val)/100)
ans = '0.07%'
sprintf('%0.2f',str2double(val)/100)
ans = '0.07'
Should the result be '0.07' or '700%' (because your code suggests '700%' but your description of the problem suggests '0.07')? You can pick the command that does the right thing.

Products

Community Treasure Hunt

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

Start Hunting!