in my code I need to put a String contained inside a map in a Decimal variable. Now I have 2 problems, the first one is the format of the String because it can contain ' , ' and ' . ' e.g. '21,31' or '3.124,23', the second one is that when I use Decimal.ValueOF(string) method System gives me "invalid decimal error" despite my code. Here my code:
[...]
if(fieldMapped.contains('UnitPrice')){
System.debug(mapFieldColumn.get('UnitPrice')[t].right(4));
//controll over price format
if(mapFieldColumn.get('UnitPrice')[t]!=''){
if((mapFieldColumn.get('UnitPrice')[t].right(4)).contains('.')){
mapFieldColumn.get('UnitPrice')[t]=mapFieldColumn.get('UnitPrice')[t].remove(',');
}else if((mapFieldColumn.get('UnitPrice')[t].right(4)).contains(',')){
mapFieldColumn.get('UnitPrice')[t]=mapFieldColumn.get('UnitPrice')[t].remove('.').replace(',','.');
}else{
mapFieldColumn.get('UnitPrice')[t]='0';
}
oli.UnitPrice = Decimal.ValueOf(mapFieldColumn.get('UnitPrice')[t]);
}
}
[...]
The system debug shows the error: "Exception: System.TypeException: Invalid decimal: € 28836.81 ". The String I was trying to cast is = "2.8836,81"
((Decimal) stingVariable)
.