How to represent percentage values in Matlab App Designer

4 ビュー (過去 30 日間)
Travis Head
Travis Head 2022 年 4 月 2 日
回答済み: Voss 2022 年 4 月 2 日
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%

回答 (1 件)

Voss
Voss 2022 年 4 月 2 日
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.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by