Table Decimal field rounding when set to ? decimals

Zancard

New Member
I have a decimal field on one of my tables that has the decimals option set to ?. What I've read in the documentation says that having a non-numeric value here should keep it from forcing a specific number of decimals, but when I try to assign a value to this field it is rounding to the nearest whole number.
Field-Name: field1
Data-Type: decimal
Initial: 0
Label: field1
Mandatory: no
Format: ->>,>>9.99
Decimals: ?
Code:
FIND FIRST bTest EXCLUSIVE-LOCK.
ASSIGN bTest.field1 = 1.23.

DISPLAY bTest.field1.
When I run this the result I get in the table is 1.00.
Code:
DEFINE VARIABLE handle AS HANDLE  NO-UNDO.

FIND FIRST bTest EXCLUSIVE-LOCK.
ASSIGN handle = BUFFER bTest:BUFFER-FIELD("field1").

ASSIGN handle:BUFFER-VALUE = 3.39.

DISPLAY bTest.field1
If I do this instead then I properly get 3.39 in the table and it works like I would expect. I've tried doing this with triggers disabled so I'm sure I don't have some strange code altering it elsewhere.

Can anyone tell me what I've done wrong to have it rounding like this? Is having "?" not the correct way? In my circumstance I am not able to change the decimals attribute in the database since I do not own it.
 
Last edited:

andre42

Member
I've only seen a decimals value of ? for other data types, but it seems that ? is legal. You are basically saying you don't want any rounding which is equivalent to full precision, so you would have to set 10 decimals which is the maximum precision Progress allows.

Just had a quick look in the OpenEdge Help:
The entry on the DECIMALS attribute for the Buffer-field object handle says
When DECIMALS is set, the AVM rounds off any source that you assign to BUFFER-VALUE to the specified number of decimal places before completing the assignment. If DECIMALS is not set, the AVM rounds the value off to 10 decimal places if necessary.
which sounds like the behavior in your second example.

The entry on the decimal data type says
The Data Dictionary allows you to set the Decimals field to unknown ("?").
Note: Setting the Decimals field to "?" can result in a loss of data. The Data Dictionary will truncate decimal values when performing a dump and load if this field is set to unknown.

I would expect the behaviour in your first example. I find it interesting that you can store more decimals using the buffer-field handle, but the OpenEdge Help seems to agree. I probably wouldn't use this method since this inconsistent behavior seems quite confusing.
 

Zancard

New Member
The Data Dictionary allows you to set the Decimals field to unknown ("?").
Note: Setting the Decimals field to "?" can result in a loss of data. The Data Dictionary will truncate decimal values when performing a dump and load if this field is set to unknown.
This is really useful information. I haven't been able to find this note anywhere in my documentation. I've looked all over the decimals data type entry for it. I wonder if I have an outdated version.

I'll bring this info up to the guys in charge and see what they say about it. They were under the same impression that "?" should have been not rounding at all. I appreciate the help.
 

andre42

Member
This is really useful information. I haven't been able to find this note anywhere in my documentation. I've looked all over the decimals data type entry for it. I wonder if I have an outdated version.
The oldest version I have installed on my machine is 10.2B. The text reads the same there. (To be precise: OpenEdge Help, entry on Data Types, Decimal.)
 

TomBascom

Curmudgeon
Depending on this sort of behavior is very unwise.

There is no "no rounding at all" option and there cannot be. That would require infinite precision which is not a feature of the decimal data type.

If you want maximum precision set decimals to 10.
 
Top