How to display a number as $xxx,xxx.xx or even xxxx.xx rather than -4.8e-001
Mostra commenti meno recenti
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 Commento
Oleg Komarov
il 23 Mar 2012
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?
Risposta accettata
Più risposte (2)
Majid Al-Sirafi
il 24 Mar 2012
0 voti
Wonderful answer dear...
thank you very much,I also need this answer
Majid Al-Sirafi
il 24 Mar 2012
0 voti
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 Commenti
Oleg Komarov
il 24 Mar 2012
Majid, you're stubborn.
It's not a matter what out1 IS, but what you see.
out1 is the same as 31356.342, but it's DISPLAYED as 3.135634200000000e+04.
Now you can type in the cmd window format bank, or you can use sprintf to FORMAT the DISPLAY. The number in out1 DOESN'T change.
Oleg Komarov
il 24 Mar 2012
To get it straight, try:
isequal(3.135634200000000e+04,31356.342)
Majid Al-Sirafi
il 24 Mar 2012
I know that dear
thank you very much
Oleg Komarov
il 24 Mar 2012
Then I don't understand you.
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!