|
Taking control of display decimals |
Top Previous Next |
|
A potential frustration with GAMS display output involves numerical formatting. Consider the example dispnum.gms. There I define the table DATA with rather disparate numbers. A resultant display of DATA yields
---- 8 PARAMETER DATA index21 index22 index11 1.000000E-5 1.000000E+7 index12 3.720 200.100
In that display GAMS mixes together numbers in exponential and normal format with the default being a print out of three decimal places. If such a display is unsatisfactory, there are several ways of altering its appearance.
option data:1:1:1;
which displays this item with one decimal place, yielding
---- 10 PARAMETER DATA index21 index22 index11 1.000000E-5 10000000.0 index12 3.7 200.1
Here, GAMS overrides the decimals choice to insure the small number does not become zero, but I don't get the exponential display for the large number as it fits.
option decimals=2;
---- 13 PARAMETER data2
index21 index22
index11 1.000000E-5 10000000.00 index12 3.72 200.10
Note, GAMS still overrides the decimals choice to insure the small number does not become zero.
data2(index1,index2)$(data2(index1,index2) lt 0.01)=0;
sets all numbers to zero which are less than 0.01, yielding
---- 14 PARAMETER DATA2 index21 index22 index11 _____ 10000000.0 index12 3.7 200.1
Note one needs to employ absolute value if negative numbers are present i.e. using a command like:
data2(index1,index2) $(abs(data2(index1,index2) lt 0.01))=0;
data2(index1,index2) $(data(index1,index2) gt 10000)=inf;
yielding
---- 18 PARAMETER DATA2 index21 index22 index11 1.000000E-5 +INF index12 3.720 200.100
data2(index1,index2)=round(data(index1,index2),0);
data4(index1,index2)$data2(index1,index2)= 100*(data3(index1,index2)/data2(index1,index2)-1); data4(index1,index2) $(abs(data4(index1,index2)) lt 0.1)=0; data4(index1,index2)$(data2(index1,index2) eq 0)= na;
Here I set small percentage changes to zero but are careful to use absolute values so negative changes are not zeroed out. I also report numbers that would report percentage changes from a base of zero with the coding "na". The result is (dispnum.gms)
---- 29 PARAMETER DATA4 index21 index22 index11 NA index12 80.6 1.5 |