function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
james7630james7630 

String with $ sign and commas causes failure

I have a string that is a currency from excel and im importing it into salesforce into a currency field. It fails on bigger numbers that have a comma, I am trying to remove the $ and the commas but it doesnt work.

 

for(String fi: row)
{
Decimal di = 0.0;
if(fi.contains('$'))
{
fi = fi.trim();
fi = fi.replace(',','');
fi = fi.replace('$','');
di = Double.valueOf(fi);
}

 

error

Caused by: System.TypeException: Invalid double: "$6546456 "

Best Answer chosen by Admin (Salesforce Developers) 
james7630james7630

solution, remove the double quotes..


james7630 wrote:

I have a string that is a currency from excel and im importing it into salesforce into a currency field. It fails on bigger numbers that have a comma, I am trying to remove the $ and the commas but it doesnt work.

 

for(String fi: row)
{
Decimal di = 0.0;
if(fi.contains('$'))
{
fi = fi.trim();
fi = fi.replace(',','');
fi = fi.replace('$','');
di = Double.valueOf(fi);
}

 

error

Caused by: System.TypeException: Invalid double: "$6546456 "


 

 

for(String fi: row)
{
Decimal di = 0.0;
if(fi.contains('$'))
{
fi = fi.remove('$');
fi = fi.remove(',');
fi = fi.remove('"');
di = Double.valueOf(fi);
}