Path: news.mathworks.com!not-for-mail
From: "jay vaughan" <jvaughan5.nospam@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: decimal precision
Date: Tue, 13 May 2008 18:43:03 +0000 (UTC)
Organization: harvard
Lines: 21
Message-ID: <g0cnfn$6$1@fred.mathworks.com>
References: <g0cmpc$gjg$1@fred.mathworks.com>
Reply-To: "jay vaughan" <jvaughan5.nospam@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210704183 6 172.30.248.37 (13 May 2008 18:43:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 18:43:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215048
Xref: news.mathworks.com comp.soft-sys.matlab:468221


"Young Ryu" <ryuyr77@gmail.com> wrote in message
<g0cmpc$gjg$1@fred.mathworks.com>...
> Hi-
> 
> I'd like to round at 4th decimal point. For example, 
> 
> 1.41536664
> => 1.415
> 
> how can I round at specific precision? There is no syntax  
> in "round" function.
> 
> Thanks!

n = 1.41536665;
% you could multiply, round, then divide
num_dig = 4;
n_rounded = round(n*(10^num_dig))/(10^num_dig);

% or for display purposes only you can use
num2str(n,'%.4f')