I am new to Apex and trying to convert Euro to USD and save it in a custom field 'measure'. Here is my code-

CurrencyType conversionRate = [SELECT conversionrate from currencytype where isocode = 'Eur'];
 newProduct.measure__c.= opplineItem.Price / (conversionRate);  

I get the following error

Arithmetic expressions must use numeric arguments.

What is the best way to convert conversionRate to decimal. Is there anything like integer.valueof() to convert to decimal? Thank you

  • 2
    From what I see in your code, you are trying to divide decimal (opplineItem.Price) by CurrencyType (conversionRate). CurrencyType is not decimal and not numeric either. What you need to do is actually get the conversionrate from CurrencyType variable which is by coincidence also named conversionRate conversionRate.conversionRate. It'd be better if you named the CurrencyType variable differently, something like CurrencyType curType = [SEL...], and then access conversionrate like curType.conversionrate . It'd be clearer
    – Eduard
    Feb 13, 2020 at 8:47
  • Hi Eduard, it worked! thank you for suggesting to change variable name.
    – Indira
    Feb 13, 2020 at 17:51

1 Answer 1


conversionRate (the one with capital R) is a CurrencyType object which is returned by the SOQL.

What you should be doing is :

newProduct.measure__c.= opplineItem.Price / (conversionRate.conversionrate); 
  • Hi Chirag, thank you for helping. It works now.
    – Indira
    Feb 13, 2020 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .