Strange problem with numbers

Post Reply
User avatar
Thomas Grueninger
Posts: 18
Joined: Fri Oct 14, 2005 5:15 pm
Location: Germany

Strange problem with numbers

Post by Thomas Grueninger »

Hello,

i have a strange Problem with numbers.

for n:=1.8 to 10.8 step .5
? str(n,22,18)
next

1.800000000000000000
2.300000000000000000
2.800000000000000000
3.300000000000000000
3.800000000000000000
4.300000000000000000
4.800000000000000000
5.300000000000000000
5.800000000000000000
6.300000000000000000
6.800000000000000000
7.300000000000000000
7.800000000000000000
8.300000000000001000
8.800000000000001000
9.300000000000001000
9.800000000000001000
10.300000000000000000
10.800000000000000000

Tested with xHarbour 1.2.3, BCC7 and xHarbour 1.2.0., BCC5
Same Result

Have anyone a solution?

Regards
Thomas Grueninger
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Strange problem with numbers

Post by karinha »

maybe.

Code: Select all

#include "FiveWin.ch"

function Main()

   LOCAL N := 0

   for n:=1.8 to 10.8 step .5

      ? str(n,22,18)

      N = N + .1

   next

Return Nil

/*
1.800000000000000000
2.300000000000000000
2.800000000000000000
3.300000000000000000
3.800000000000000000
4.300000000000000000
4.800000000000000000
5.300000000000000000
5.800000000000000000
6.300000000000000000
6.800000000000000000
7.300000000000000000
7.800000000000000000
8.300000000000001000
8.800000000000001000
9.300000000000001000
9.800000000000001000
10.300000000000000000
10.800000000000000000
*/
 
João Santos - São Paulo - Brasil
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Strange problem with numbers

Post by tiaofw »

Good Morning.

Full is a bug this xHarbour because this returning garbage in decimals.

It is good to inform xHarbour developers.

bye.
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Strange problem with numbers

Post by tiaofw »

Enrico understood, then the solution would be to truncate the decimals?

I did not understand what the problem is that this variation is causing him.


Thanks
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
User avatar
Thomas Grueninger
Posts: 18
Joined: Fri Oct 14, 2005 5:15 pm
Location: Germany

Re: Strange problem with numbers

Post by Thomas Grueninger »

It works simple. You never come to 8.8

local n:=8.8
MsgInfo(str(n,20,18))
---------------------------
Information
---------------------------
8.800000000000001000
---------------------------
OK
---------------------------
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Strange problem with numbers

Post by Enrico Maria Giordano »

Clipper, Harbour, xHarbour floating-point system supports up to 15 significant digits.

EMG
Post Reply