Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: decimal precision
Date: Tue, 13 May 2008 18:57:24 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 28
Message-ID: <g0coak$1bd$1@canopus.cc.umanitoba.ca>
References: <g0cmpc$gjg$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1210705044 1389 192.70.172.160 (13 May 2008 18:57:24 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 13 May 2008 18:57:24 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:468225


In article <g0cmpc$gjg$1@fred.mathworks.com>,
Young Ryu <ryuyr77@gmail.com> wrote:

>I'd like to round at 4th decimal point. For example, 

>1.41536664
>=> 1.415

>how can I round at specific precision?

It is not (generally) possible to round fractions at a decimal precision,
The exceptions have to do with rounding to integers divided by exact powers
of 2, such as 1/2, 1/4, 3/4, and so on.

There is no exact representation in binary floating point for 0.1 (1/10),
just as there is no exact representation in base 10 decimal expression
for 1/3. If your number does not happen to round to one of those
power-of-2 fractions I mentioned before, then there will always be
something left over -- it might be 15 decimal places further down, but
it will be there.

You -can-, though, convert numbers to character strings that
have specific numbers of decimal places, for "presentation purposes"
as the other poster mentioned.
-- 
  "He wove a great web of knowledge, linking everything together, 
  and sat modestly at a switchboard at the center, eager to help."
                                              -- Walter Kerr