Can I change the decimal symbol from a dot to a comma?
Moderator: aileen
Forum rules
Please ask questions in the other sub-forums
Please ask questions in the other sub-forums
Can I change the decimal symbol from a dot to a comma?
Can I change the decimal symbol from a dot to a comma?
Re: 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:
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:
or
and get
Code: Select all
dummy;new-york;chicago;topeka
seattle;2,5;1,7;1,8
san-diego;2,5;1,8;1,4
Code: Select all
* 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;
Code: Select all
* 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;
Code: Select all
---- 14 PARAMETER data
new-york chicago topeka
seattle 2.500 1.700 1.800
san-diego 2.500 1.800 1.400