User Tools

Site Tools


interfaces:can_i_change_the_decimal_symbol_from_a_dot_to_a_comma

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

interfaces:can_i_change_the_decimal_symbol_from_a_dot_to_a_comma [2007/09/28 16:42] (current)
Line 1: Line 1:
 +====== 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:
 +<​code>​
 +dummy;​new-york;​chicago;​topeka
 +seattle;​2,​5;​1,​7;​1,​8
 +san-diego;​2,​5;​1,​8;​1,​4
 +</​code>​
 +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:
 +<​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;
 +</​code>​
 +or 
 +<​code>​
 +* 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>​
 +and get 
 +<​code>​
 +----     14 PARAMETER data  ​
 +
 +             ​new-york ​    ​chicago ​     topeka
 +
 +seattle ​        ​2.500 ​      ​1.700 ​      1.800
 +san-diego ​      ​2.500 ​      ​1.800 ​      1.400
 +</​code>​
 +
  
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY interfaces/can_i_change_the_decimal_symbol_from_a_dot_to_a_comma.txt ยท Last modified: 2007/09/28 16:42 (external edit)