Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to round to 2 decimal?
Replies: 12   Last Post: Oct 18, 2015 7:19 AM

 Messages: [ Previous | Next ]
 PAR Posts: 273 Registered: 12/7/04
Re: how to round to 2 decimal?
Posted: Mar 4, 2008 10:47 AM

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fqjpru\$lpj\$1@canopus.cc.umanitoba.ca>...
> In article <fqjpgm\$3hp\$1@fred.mathworks.com>, Deo
<spliers@hotmail.com> wrote:
> >hey, how can I set my matlab program to round all the
> >double numbers to 2 decimals

>
> You cannot. There is no exact representation in floating point
> for .01, .02, up to .99, except for 0.25, 0.50, and 0.75 which
> have exact representations. If you were to try to round
> (say) pi to 2 decimal places then the value stored internally
> would not correspond to 3.14 but instead to approximately
> 3.14 + 2e-15
>
> If you are only attempting to change what is displayed when
> you specifically ask to output something, then you can
> format the numbers using num2str or sprintf() using a format
> such as '%0.2f' .
> --
> So you found your solution
> What will be your last contribution?
> -- Supertramp (Fool's Overture)

x = round((x*100))/100

Date Subject Author
3/4/08 Deo
3/4/08 Walter Roberson
3/4/08 PAR
10/18/15 Chaman Lal Dewangan
3/4/08 PAR
3/4/08 J
3/4/08 Walter Roberson
3/6/13 Nasser Abbasi
11/14/13 Marco
11/14/13 Derek Goring
6/9/15 yan mercal
6/9/15 Steven Lord