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
willingwilling 

Convert a double to Integer

I need to multiply two numbers , one of them is integer and other is Double.
It is not allowing me to multiply.

I am using the following syntax currently:    time_cov is double
  
      Integer.valueOf(String.valueOf(time_cov ))

It does not error out but is not giving me result.

Is there a better way or any other way.

Thanks
mikefmikef
willing:

In Java you would use the cast operator to perform multiplication between ints, and doubles.

I haven't found any documentation for this but it seems Apex handles the cast for you.

I tested and this works:

Code:
Integer x = 2;
Double y = 2.0;

for(Account a : Trigger.new){
 a.YOUR_CUSTOM_FIELD__c =  x * y;
}

And this works:


Code:
Integer x = 2;
for(Account a : Trigger.new){ 
     a.YOUR_CUSTOM_FIELD__c =  x * a.YOUR_DOUBLE_FIELD__c; 
}

 Hope this helps


 

willingwilling
Thanks Mike,

It did work