User Tools

Site Tools


gams:export_only_rounded_numbers_from_gams_to_excel

How do I export only rounded numbers from GAMS to Excel?

Q: When unloading data from GAMS to Excel with GDX, is it possible to round numbers or choose the number of decimal to be included in the Excel files?

There is no explicit option to round numbers when writing to an Excel file, but you can round within GAMS before writing the data to GDX. The following will round the parameter abc to two decimal places, export it to Excel, and call Excel with the correct file extension (depending of the version of Excel installed):

$if NOT set fn $set fn 'abc'
set i /i1*i3/;
parameter abc(i);
abc(i)=normal(0,1);
abc(i) = round(abc(i),2);
display abc;
execute_unload '%fn%.gdx' abc;
execute 'GDXXRW.EXE %fn%.gdx par=abc rng=a1';
scalar R;
execute 'xlstalk.exe -E %fn%.xls';
R = errorlevel;
if( R = 1,
  execute 'shellexecute.exe %fn%.xls';
else
  execute 'shellexecute.exe %fn%.xlsx';
  );
gams/export_only_rounded_numbers_from_gams_to_excel.txt · Last modified: 2010/06/21 11:44 by support