+ Start a Discussion
Raghu Ch 2Raghu Ch 2 

Invalid decimal error while parsing .csv file using visualforce

Hi,

I am parsing .csv file in visualforce. While parsing a percentage column from .csv file and assigning to the a percentage column (FMC_Ownership__c) in salesforce. I get the below error.

Invalid decimal error.

Code below let me know what the issue could be.

public class upload{

public string fileName{get;set;}
    public blob fileBody{get;set;}
    public attachment att{set;get;}
    
    public String[] filelines = new String[]{};
    
    public string nameFile{get;set;}


nameFile=fileBody.toString();
             //nameFile=EncodingUtil.base64Encode(fileBody);
           filelines = nameFile.split('\n');
            system.debug('#######' + filelines.size());
            
            List<Acquisition__c> aqList=new List<Acquisition__c>([Select Id,Pro_Forma_Version__c
                                            from Acquisition__c
                                            where Id=:ID]);
            
            aqUpdaList.clear();
            
            Map<Id,Acquisition__c> aqMapUpdate=new Map<Id,Acquisition__c>();
             for (Integer i=0;i<filelines.size();i++)
                {
                    String[] inputvalues = new String[]{};
                    inputvalues = filelines[i].split(',');
                    system.debug('#######' + inputvalues[1]);
                    for(Acquisition__c a:aqList){
                    a.Pro_Forma_Version__c=inputvalues[0];
                    a.FMC_Ownership__c=decimal.valueof(inputvalues[1].trim());
                    //Decimal.valueOf(inputvalues[1]);
                    //decimal.valueOf(inputvalues[1]);
                    aqUpdaList.add(a);
                    aqMapUpdate.put(a.Id,a);
                    }
                    //system.debug('#######' + Decimal.valueOf(inputvalues[1]));
                }
            
                //update aqUpdaList;
                update aqMapUpdate.values();
}