User Tools

Site Tools


interfaces:can_i_change_the_decimal_symbol_from_a_dot_to_a_comma

Can I change the decimal symbol from a dot to a comma?

The short answer is no, this is not possible within GAMS. However it only becomes an issue when importing data in ASCII format (i.e. csv-files). Here is a simple example (input.csv) generated with the German regional settings of Windows:

dummy;new-york;chicago;topeka
seattle;2,5;1,7;1,8
san-diego;2,5;1,8;1,4

To change the comma into a dot and the semicolon into a comma we just use one of the POSIX tools, which are part of any GAMS system and write a few lines of GAMS code:

* translate , to . using tr
$call "tr , . <input.csv >temp.csv"
* translate ; to , using tr
$call "tr ; , <temp.csv >output.csv"
table data(*,*)
$ondelim
$include output.csv
$offdelim
display data;

or

* translate , to . and ; to , using sed
$onecho > sedscript
s/,/./g
s/;/,/g
$offecho
$call sed -f sedscript input.csv > output.csv
table data(*,*)
$ondelim
$include output.csv
$offdelim
display data;

and get

----     14 PARAMETER data  

             new-york     chicago      topeka

seattle         2.500       1.700       1.800
san-diego       2.500       1.800       1.400
interfaces/can_i_change_the_decimal_symbol_from_a_dot_to_a_comma.txt · Last modified: 2007/09/28 14:42 (external edit)