Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to adjust number format
Date: Tue, 16 Dec 2008 19:14:02 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 30
Message-ID: <gi8ulq$iiv$1@fred.mathworks.com>
References: <gi8he3$dvs$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1229454842 19039 172.30.248.38 (16 Dec 2008 19:14:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 16 Dec 2008 19:14:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:507368


"sujata" 
> Does anyone know if you have a large number like for instance 1500000 how it can be adjusted to a nicer format such as 1,500,000...

one of the many (here vectorized) solutions

% the data
     mrk=','; % <- select your marker
     a=[-50125,1,1500000,1250125,int64(inf)];
% the engine
     clear r;
     v=sprintf('%30.0f',a); % - works up to INTMAX('uint64')
     v=reshape(v,[],numel(a));
     vx=repmat([1,1,1,0]~=0,1,10);
     vx(end)=[];
     r(vx,:)=v;
     r(~vx,:)=mrk;
     r=cellstr(r.');
     r=strrep(r,[' ',mrk],'');
     r=strtrim(r);
% the result
     disp(r);
%{
     '-50,125'
     '1'
     '1,500,000'
     '1,250,125'
     '9,223,372,036,854,775,800'
%}

us