Floating point to string conversion
The default formatting of a DECIMAL(P)
, SMALLFLOAT
and
FLOAT
adapts to the significant digits of the value.
Floating point decimal types (like DECIMAL(5)
) can store a large range of
values, with a variable number of digits after the decimal point: For example, a
DECIMAL(5)
can store 12345 as well as 0.12345. See DECIMAL(p,s) for more details about floating point decimal
types.
With Genero 2.50, the conversion to string from a DECIMAL(P)
,
FLOAT
and SMALLFLOAT
has been revised, to keep all
significant digits and avoid data loss.
Before Genero 2.50, floating point decimals converted to strings were formatted with 2
decimal digits by default, which could lead to data loss. See following example using a
DECIMAL(12)
:MAIN
DEFINE str STRING, dec12, dec12_bis DECIMAL(12)
LET dec12 = 10.12999
LET str = dec12
DISPLAY str
LET dec12_bis = str
DISPLAY (dec12 == dec12_bis)
END MAIN
Prior to Genero 2.50, the above code displayed:
10.13
0
Starting with Genero 2.50, all significant digits are kept, which allows for proper decimal
data serialization:
10.12999
1
Prior to Genero 2.50, floating point decimal values conversion of huge values could also
lose digits in the whole part of the number; the width of the result was never longer than p + 2.
Starting with Genero 2.50, all significant digits of a floating point decimal are kept in the result
string:
Values Vers<2.50 Vers>=2.50
-------------------------------------------------
1.23456e123 1.23456e123 1.23456e123
1.23456e40 1.235e40 1.23456e40
123.456 123.46 123.456
123456.0 123456.0 123456.0
0.123456 0.12 0.123456
0.0123456 0.01 0.0123456
0.00123456 0.00 0.00123456
1.23456e-08 0.00 1.23456e-08
If you expect that any
DECIMAL(P)
to string conversion rounds to 2 digits,
define the following FGLPROFILE
entry:fglrun.decToCharScale2 = true
Note: Do not use this configuration parameter unless you have migration issues. This
configuration parameter applies only to
DECIMAL(P)
types,
FLOAT
and SMALLFLOAT
conversions to string is not
impacted.