+ Start a Discussion
mikefmikef 

Integer.valueOf(Double) returning a Double

Hi:

I am using Integer.valueOf and passing a double in, but I am getting back a double.

Anyone have this issue as well?


Code:
public class ProposalContractEndDate {

public static void stampContractEndDate(Proposal__c[] proposals){
for(Proposal__c p : proposals){
if(p.Contract_Start_Date__c != null &&
p.Contract_Term_Months__c != null){
p.Contract_End_Date__c = getContractEndDate(p.Contract_Start_Date__c,Integer.valueOf(p.Contract_Term_Months__c));
}
}
}

public static Date getContractEndDate(Date startDate, Integer termInMonths){
Date newDate = startDate.addMonths(termInMonths);
return newDate;
}

}

 

Error,
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ProposalTrigger caused an unexpected exception, contact your administrator: ProposalTrigger: execution of BeforeUpdate caused by: System.TypeException: Invalid integer: 12.0: Class.ProposalContractEndDate.stampContractEndDate: line 22, column 86


Message Edited by mikef on 12-22-2008 02:13 PM
JeremyKraybillJeremyKraybill
Use the Double.intValue() method instead, i.e.:
Code:
p.Contract_Term_Months__c.intValue()

 HTH

Jeremy Kraybill
Austin, TX

mikefmikef
Thank you that worked swimmingly.