[SalesForce] Compile Error: Illegal assignment from Decimal to Integer

itemlst.Quantity = templook[i].Quantity__c;

Here Quantity is of integer type and Quantity_c is of decimal type.How can I convert Quantity_c into Integer

Best Answer

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_integer.htm

itemlst.Quantity = integer.valueOf(templook[i].Quantity__c);

Integer.valueOf will work.

Edit:

 Decimal myDecimal = 4.12;
 Integer a=myDecimal.intValue();
  System.debug('*****'+a);

I used Decimal.intValue() and it works as shown.

Related Topic