[SalesForce] System.TypeException: Invalid decimal Error in apex

I have a currency field in object. I am assigning value to it in apex

For US users: the currency format is 241,500.00 so when i apply decimalof on this i am getting 241500000.00.

But for Eur users: the currency format is 241.500.00000, so when i apply decimalof on this i am getting Invalid decimal: 241.500.00000

String s = 241.500.00000 or 241,500.00 ; 
mar.flowvalue__c = decimal.valueOf(s);

Could you please help me to resolve this issue

Best Answer

Unfortunately while the Decimal class has a format method:

format()
Returns the String value of this Decimal using the locale of the context user.

there is no equivalent parse method that respects the user's locale.

The approach that side-steps the problem is to use things like <apex:inputField/> that does respect the locale in the string conversion and stores a Decimal value after the parsing rather than a String. Otherwise you will have to write your own locale aware parse method.