How to display a number as $xxx,xxx.xx or even xxxx.xx rather than -4.8e-001

조회 수: 16 (최근 30일)
I have a disp command that returns the status
num2str(total,'%i')
For some reason it is returning the totals as
-4.808337e-001
How can I have it return smply as .048 or .04?
Most of the amounts are currenty so ideally formatted $xxx,xxx.xx would be perfect
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 23일
Which part of the answers you got on
http://www.mathworks.com/matlabcentral/answers/32171-function-to-format-number-as-currency
didn't work out?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 3월 23일
sprintf('%.2f', -4.808337e-001)
>> -0.48
I do not see a sufficient and reliable method to display this as ".048" or ".04". Do you really want to omit the leading sign and zeros and divide the fractional part by 10?

추가 답변 (2개)

Majid Al-Sirafi
Majid Al-Sirafi 2012년 3월 24일
Wonderful answer dear...
thank you very much,I also need this answer

Majid Al-Sirafi
Majid Al-Sirafi 2012년 3월 24일
hi dear i have approximately same this problem look at this code
n = 3456;
% Separate them
na = num2str(n) - '0';
% substitute the 4 (position 2) with 13
na(2) = 13;
% Recombine
out = str2double(sprintf('%d',na)); %out will be 31356 but double
out1 = out + .342; % out1 will be 3.135634200000000e+04 but double
out2=sprintf('%.3f',out1); %out2 will be 31356.342 but character
but I want 31356.342 but double
thank you dear
  댓글 수: 4
Majid Al-Sirafi
Majid Al-Sirafi 2012년 3월 24일
I know that dear
thank you very much

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by