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
Indira Reddy 1Indira Reddy 1 

How to convert currency to decimal

Hi All,
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'. I need to convert conversionRate to decimal. Is there anything like integer.valueof() to convert to decimal.
Thank you
Best Answer chosen by Indira Reddy 1
Danish HodaDanish Hoda
Hi Indira,
please use newProduct.measure__c.= opplineItem.Price / (conversionRate.conversionrate);  

All Answers

Danish HodaDanish Hoda
Hi Indira,
please use newProduct.measure__c.= opplineItem.Price / (conversionRate.conversionrate);  
This was selected as the best answer
Indira Reddy 1Indira Reddy 1
Hi Danish, it worked! Thank you!