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
VisualForceVisualForce 

Convert Double to Integer

HI..
 
        How to convert double value into integer..
 
My code is
 
integer percent;
double total;
public integer getPercentage()
{
      percent=integer.valueof(total);
      return percent;
}
 
here total is double value..
 
While I click runtest I got
 
System error : Type Exception
Invalid Integer 0.0
 
 
I need a round value...
 
Now I am using
 
double percent;
double total;
public double getPercentage()
{
      percent=Math.round(total);
      return percent;
}
 
I got a answer like 10.0 (with .0) ..  I want to display 10 only..
 
integer percent;
double total;
public integer getPercentage()
{
      string temp=string.valueof(total);
      percent=integer.valueof(temp);
      return percent;
}
 
          The above code is deployed without error.. When I run this page I got a error like invalid integer 10.334532421
 
 
This visual force page is used for PDF generation ...
 
Best Answer chosen by Admin (Salesforce Developers) 
VisualForceVisualForce

Thanks for ur reply..

I got error Method does not exist while I use this code

x = double.intValue(y);

But I change into

x = y.intValue();

Now its work...

Thanks once again....

 

 

 

All Answers

kevinbnpowerkevinbnpower
Double static method...

Code:
integer x;
double y;

x = double.intValue(y);

 


VisualForceVisualForce

Thanks for ur reply..

I got error Method does not exist while I use this code

x = double.intValue(y);

But I change into

x = y.intValue();

Now its work...

Thanks once again....

 

 

 

This was selected as the best answer
kevinbnpowerkevinbnpower
Sorry! Mixing my languages ;)
Adithya SreyajAdithya Sreyaj
Double x = double.valueOf("double_value_here");
Integer y = x.intValue();

This is the correct format. Hope it helps you.