Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d1g2000hsg.googlegroups.com!not-for-mail
From: zia <mkhawarzia@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to round to 2 decimal?
Date: Sat, 28 Jun 2008 15:18:35 -0700 (PDT)
Organization: http://groups.google.com
Lines: 59
Message-ID: <58baeb5c-160f-44d9-b317-b78a927aa804@d1g2000hsg.googlegroups.com>
References: <fqjpma$66c$1@fred.mathworks.com> <fqnaea$370$1@fred.mathworks.com> 
NNTP-Posting-Host: 71.172.193.244
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1214691516 19627 127.0.0.1 (28 Jun 2008 22:18:36 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 28 Jun 2008 22:18:36 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d1g2000hsg.googlegroups.com; posting-host=71.172.193.244; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) 
Xref: news.mathworks.com comp.soft-sys.matlab:476435


On Jun 28, 6:09=A0pm, "Omar U. Florez" <omarflore...@gmail.com> wrote:
> sprintf('%g',round(-sorted_values(j)*100)/100)
>
> where the specifier '%g' avoids showing the last
> or 'insignificant' zeros and shows only the two decimals
> product of multiplying by 100.
>
> >> sprintf('%g',round(pi*100)/100)
>
> ans =3D
> 3.14
>
> "carlos lopez" <clv2clv_000000...@adinet.com.uy> wrote in
> message <fqnaea$37...@fred.mathworks.com>...
>
> > "Deo " <spli...@hotmail.com> wrote in message
> > <fqjpma$66...@fred.mathworks.com>...
> > > hey, how can I set my matlab program to round all the
> > > double numbers to 2 decimals
> > Hello Deo:
> > Aside from the other answers, I believe that you should
> > clearly state which one is your real wish:
> > a) perform every calculation in fixed point, using only
> two
> > decimals
> > b) display every final result as a real with just two
> decimals.
> > The other answers are related with the option b), but they
> > do not preclude that all the calculations will be carried
> > out to full double precision, and only later displayed as
> > you wish.
> > On the other hand, if you need something as described in
> a),
> > you should consider other approaches. To some extent, two
> > decimal arithmetic can be simulated with integer
> arithmetic
> > after multiplying the inputs by 100. Depending on your
> > matlab version, it will be simpler (or not) to achieve
> that.
> > Let us know about your option: namely a) or b)
> > Regards
> > Carlos


Hello,

Try this

x =3D 1.23456

quant(x,2)


function output =3D quant(number,digit)

output =3D round(number.*(10 ^ digit))./(10 ^ digit);


--Zia