From: Walter Roberson <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: floating point percision
Date: Fri, 19 Nov 2010 16:25:29 -0600
Organization: Canada Eat The Cookie Foundation
Lines: 25
Message-ID: <ic6th4$6tl$>
References: <ic6sal$78f$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: 1290205541 7093 (19 Nov 2010 22:25:41 GMT)
NNTP-Posting-Date: Fri, 19 Nov 2010 22:25:41 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20101027 Thunderbird/3.0.10
In-Reply-To: <ic6sal$78f$>
Xref: comp.soft-sys.matlab:688489

On 10-11-19 04:05 PM, Eman wrote:

> how can I determine the number of digits after the decimal point?
> I mean:
> If I need 2 digits after decimal point, If a=74.67859 it should be a=74.68
> If I need 3 digits after decimal point, If a=74.67859 it should be a=74.679
> note: I need to use the new value not only format them in printing.

The only way to do that is to use symbolic numbers with the symbolic toolkit, 
or fixed-point numbers with the fixed-point toolbox.

You can use transformations such as

round(a .* 10^D) ./ 10^D

where D is the number of digits you want after the decimal place. This will 
not, however, round to *exactly* 74.68: it would instead round to 

When you use binary floating point numbers, the only numbers with two decimal 
places that can be *exactly* represented are those that end in .0, .25, .5, or 
.75 . It is not possible, for example, to exactly represent 0.1 in binary 
floating point: the closest you can get would be