1
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

1 Answer 1

4

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.

4
  • When should I use decimalvalue.intvalue();
    – Eagerin Sf
    Nov 21, 2012 at 6:47
  • salesforce.com/us/developer/docs/apexcode/Content/… Thats an instance method and you will need an decimal instance and then get the value Nov 21, 2012 at 6:52
  • I updated my answer .You may like to refer that too. Nov 21, 2012 at 6:59
  • 1
    I'm not a big fan of Decimal.intValue, means you need extra check or you'll get null pointer exception ;) Decimal d = null; System.debug(Integer.valueOf(d)); works and outputs null
    – eyescream
    Nov 21, 2012 at 8:00

You must log in to answer this question.

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