Removing comma from numbers in a 2-D Array elements

37 views
Skip to first unread message

Manikandan Murugesan

unread,
Jul 9, 2024, 4:33:42 AM (7 days ago) Jul 9
to Google Apps Script Community
I have a CSV file with multiple rows and columns. in which number have a group separator , for more than 1000.

For example 1234.56 is read as 1,234.56. 1,234.56 is recognised as text rather than number 

how to solve or convert these to number? any suggestion

Bennett, Scott

unread,
Jul 9, 2024, 8:18:20 AM (7 days ago) Jul 9
to google-apps-sc...@googlegroups.com
I threw this together. 
function replace(){
  var array = [
    ['6,234.54','5,670.87'],
    ['5,235.87','9,342.56']
  ]
 
  for(var row in array){
    for(var i=0;i<array[row].length;i++){
      array[row][i]=parseFloat(array[row][i].replace(',',''))
      Logger.log('Value: '+array[row][i]+' is a '+typeof array[row][i])
    }
  }
  Logger.log(array)
}

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/c1076c16-c468-4ee3-af77-76719b99d58cn%40googlegroups.com.


--
Scott Bennett

Message has been deleted

Manikandan Murugesan

unread,
Jul 10, 2024, 4:45:29 AM (6 days ago) Jul 10
to Google Apps Script Community
i too have same up with similar work around to resolve this
for(let x=0;x<numberOfColumns;x++){
  if(columnDataTypesMapping[x]==1){
    csvData[i][x]=csvData[i][x].replace(/,/g, '')
  }
}
Reply all
Reply to author
Forward
0 new messages