10%+10%
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yang Metin
el 13 de En. de 2021
Comentada: Steven Lord
el 13 de En. de 2021
Why 10%+10%=10?
0 comentarios
Respuesta aceptada
Alan Stevens
el 13 de En. de 2021
Because the % symbol indicates that the rest of the line is a comment. So the only non comment parameter Matlab sees is the first 10.
4 comentarios
Alan Stevens
el 13 de En. de 2021
Seems crazy! However, how about
10/100
or define your own percent function, say
percent = @(x) x/100;
Steven Lord
el 13 de En. de 2021
What do you mean by "How should I enter?" Where/how are you trying to enter this data?
Using the input function? If so accept the data as text, process that text, and finally convert that text into a number.
in = input("Enter the percentage discount: ", 's');
if endsWith(in, "%")
in = strip(in, "%");
end
inDouble = str2double(in)
Run this twice, the first time entering 10% at the prompt and the second time just entering 25.
In an inputdlg or an app? Get the data as text and proceed as I did with the input example above.
in = inputdlg("Enter the percentage discount")
In some other context like in a MATLAB script, function, or class file? If so please give more information.
Más respuestas (0)
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!