Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Bug when doing simple subraction/multiplication
Date: Wed, 24 Nov 2010 04:33:04 +0000 (UTC)
Organization: Boeing Co
Lines: 56
Message-ID: <ici4i0$77m$1@fred.mathworks.com>
References: <icho0p$bjb$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1290573184 7414 172.30.248.35 (24 Nov 2010 04:33:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Nov 2010 04:33:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:689541

"lisett " <lisvelar@gmail.com> wrote in message <icho0p$bjb$1@fred.mathworks.com>...
> I am using version R2010a of matlab, 
> in my command window simply for practicing
> 
> >> b = 6.245
> 
> b =  6.245000000000000
> 
> >> b = b- 6
> 
> b = 0.245000000000000
> 
> >> b = b *10
> 
> b = 2.450000000000001
> 
> >> b = b *10
> 
> b = 24.500000000000011
> 
> This is not an isolated problem to the numbers given in this example. 
> 
> Where are these extra values coming from and more importantly how can I do this type of shifting without receiving these errors?

As a learning aid you can use the num2strexact utility:

>> b = 6.245
b =
    6.2450
>> num2strexact(b)
ans =
6.24500000000000010658141036401502788066864013671875
>> b = b- 6
b =
    0.2450
>> num2strexact(b)
ans =
0.24500000000000010658141036401502788066864013671875
>> b = b *10
b =
    2.4500
>> num2strexact(b)
ans =
2.4500000000000010658141036401502788066864013671875
>> b = b *10
b =
   24.5000
>> num2strexact(b)
ans =
2.4500000000000010658141036401502788066864013671875e1

num2strexact can be found here:

http://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str

James Tursa