Numeric comparisons
Posted: Wed Sep 27, 2006 7:21 pm
Hi all,
Either I got crazy, or something else is happening...
I have a problem with the 32-bit that does not exist in the 16-bit, or DOS.
To better describe the problem:
1. I have a database with four CHAR fields (width 20) that hold some numbers (amounts) with four decimals in them.
Example:
Soc.Security Medicare Withholding Total Amount
1172.0200 275.2700 839.0600 2291.3500
If I get the VAL() of each database field from the above, round them to 2 decimals, then add them up, I get the result 2291.35 (CORRECT) !!!
Now, the second record in the database contains these:
Soc.Security Medicare Withholding Total Amount
1019.5000 238.4400 679.9000 1937.8400
In my loops, I need to compare if the three first values of the fields, are equal to the Total Amount.
As I state above, the first example record results to .T. (equal).
The second record, and many more records (practically all of them are equal, if I add them up they match the total amount value, which notice that it is also of CHAR type in the field, converted to VAL(), and Rounded to 2 decimals, I get the same incorrect result (.F.), when I do the comparison.
Since I made the thought that either I'm too stressed from working too much, or getting too old, I wouldn't like to mention about having problems with FWH numeric comparisons.... thus, I copied the code from the 32-bit PRG and pasted it into a stand-alone PRG which I compiled in FW 16-bit, and another one in MS-DOS.
Both the 16-bit applications came up with .T. everywhere where they should be .T. of course. To make things easier, all the fields match the Total amount in the same record.
Now I am sitting down and do nothing further because this issue has driven me crazy. I have more than 30 years in the field, and am sure that there is nothing wrong with my code... simple things, that in addition, are working perfectly in the 16-bit environment.
Can some of my friends try to reproduce and verify that the above numbers, if read from a dbf stored as characters, do not match the total amount?
I would be grateful if I receive some answer(s).
Kind regards
Evans
ps. Sorry if the numbers don't show too nice above...
Either I got crazy, or something else is happening...
I have a problem with the 32-bit that does not exist in the 16-bit, or DOS.
To better describe the problem:
1. I have a database with four CHAR fields (width 20) that hold some numbers (amounts) with four decimals in them.
Example:
Soc.Security Medicare Withholding Total Amount
1172.0200 275.2700 839.0600 2291.3500
If I get the VAL() of each database field from the above, round them to 2 decimals, then add them up, I get the result 2291.35 (CORRECT) !!!
Now, the second record in the database contains these:
Soc.Security Medicare Withholding Total Amount
1019.5000 238.4400 679.9000 1937.8400
In my loops, I need to compare if the three first values of the fields, are equal to the Total Amount.
As I state above, the first example record results to .T. (equal).
The second record, and many more records (practically all of them are equal, if I add them up they match the total amount value, which notice that it is also of CHAR type in the field, converted to VAL(), and Rounded to 2 decimals, I get the same incorrect result (.F.), when I do the comparison.
Since I made the thought that either I'm too stressed from working too much, or getting too old, I wouldn't like to mention about having problems with FWH numeric comparisons.... thus, I copied the code from the 32-bit PRG and pasted it into a stand-alone PRG which I compiled in FW 16-bit, and another one in MS-DOS.
Both the 16-bit applications came up with .T. everywhere where they should be .T. of course. To make things easier, all the fields match the Total amount in the same record.
Now I am sitting down and do nothing further because this issue has driven me crazy. I have more than 30 years in the field, and am sure that there is nothing wrong with my code... simple things, that in addition, are working perfectly in the 16-bit environment.
Can some of my friends try to reproduce and verify that the above numbers, if read from a dbf stored as characters, do not match the total amount?
I would be grateful if I receive some answer(s).
Kind regards
Evans
ps. Sorry if the numbers don't show too nice above...