Hey, So i get a problem with a code. I am suppouse to get the resut: a+b=c but this has to be written in one line and c has to have 2 decimal places (2.00/5.42 something like that).
Here is part of my code, I belive that the rest is not important in here
case '+'
a=input('Podaj wartość liczbową dla pierwszego wyrazu: ');
b=input('Podaj wartość liczbową dla drugiego wyrazu: ');
c=a+b;
disp([num2str(a),'+(',num2str(b),')=']);
disp(c);
format bank
And if i do it this way i'll get
a+b
=c
I have also tried to do it like this
disp([num2str(a),'+(',num2str(b),')=',num2str(c)]);
but then i dont have those decimal places

 채택된 답변

Chad Greene
Chad Greene 2015년 12월 8일

0 개 추천

You can use
num2str(a,'%0.2f')
to specify two decimal places.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2015년 12월 8일

답변:

2015년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by