I have issue that I want to round the double data type to two decimal places. I am writing the below apex code to do that but not working.

public Double APR_system_Volume_with_Racking_m3_Annual{get;set;}

APR_system_Volume_with_Racking_m3_Annual = ((dBBU_in_MBU * dTotal_Volume_BBU_m3) + dTotal_Volume_MBU_m3)* dMBU; 
      i = APR_system_Volume_with_Racking_m3_Annual * 10;
      APR_system_Volume_with_Racking_m3_Annual = Math.round(i);
      APR_system_Volume_with_Racking_m3_Annual = APR_system_Volume_with_Racking_m3_Annual /10;    

Still my variable APR_system_Volume_with_Racking_m3_Annual showing value like 33737.670000000006 in my visual force page. I want to format that value in apex not in visual force outputtext formatting like

<apexutputText value="{0, number, 000,000.00}">
       <apexaram value="{!Account.AnnualRevenue}" />

1 Answer 1


In Apex try the following code. I hope this should work.

Decimal annualRevenue= 0;
annualRevenue= <Calculate your value>;
Account.AnnualRevenue = annualRevenue.SetScale(2); // set the result to 2 decimal places
  • Thanks for your reply.its working fine when data type is decimal but i have my data type as double as i have wrote . because there are more workout on the same variable as well. Jun 23, 2015 at 9:29

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.