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



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

Integer.valueOf will work.


 Decimal myDecimal = 4.12;
 Integer a=myDecimal.intValue();

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

|improve this answer|||||
  • When should I use decimalvalue.intvalue(); – Eagerin Sf Nov 21 '12 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 – Mohith Shrivastava Nov 21 '12 at 6:52
  • I updated my answer .You may like to refer that too. – Mohith Shrivastava Nov 21 '12 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 '12 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.