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
Strange problem with numbers
- Thomas Grueninger
- Posts: 18
- Joined: Fri Oct 14, 2005 5:15 pm
- Location: Germany
Re: Strange problem with numbers
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
Re: Strange problem with numbers
Good Morning.
Full is a bug this xHarbour because this returning garbage in decimals.
It is good to inform xHarbour developers.
bye.
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
FWH/xharbour 15.12/PELLES C, MED, DBF
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Strange problem with numbers
No, it's the normal behaviour of the floating-point numbers.
EMG
EMG
Re: Strange problem with numbers
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
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
FWH/xharbour 15.12/PELLES C, MED, DBF
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Strange problem with numbers
Better to round it to the desired number of decimals using ROUND() function.
EMG
EMG
- Thomas Grueninger
- Posts: 18
- Joined: Fri Oct 14, 2005 5:15 pm
- Location: Germany
Re: Strange problem with numbers
It works simple. You never come to 8.8
local n:=8.8
MsgInfo(str(n,20,18))
---------------------------
Information
---------------------------
8.800000000000001000
---------------------------
OK
---------------------------
local n:=8.8
MsgInfo(str(n,20,18))
---------------------------
Information
---------------------------
8.800000000000001000
---------------------------
OK
---------------------------
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Strange problem with numbers
Clipper, Harbour, xHarbour floating-point system supports up to 15 significant digits.
EMG
EMG