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
kminevkminev 

Two Decimal Places Formatting

Hi,

 

I work with Decimal values and after performing some calculations I alway end up with numbers like 1.235555555

 

I need to limit my Decimal to precision to only 2 decimal places after the decimal point.

 

I don't seem to find method that does that.

 

Any ideas, I am sure is simple :)

 

Forgot to mention: This is entirely in Apex code!

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

Use the setScale() Methods to specify the number of Decimals

 

eg:

Decimal d = 10.032222;
System.debug(d.SetSCale(2));

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm

All Answers

Ritesh AswaneyRitesh Aswaney

Use the setScale() Methods to specify the number of Decimals

 

eg:

Decimal d = 10.032222;
System.debug(d.SetSCale(2));

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm

This was selected as the best answer
kminevkminev

Thank you, I was using the setScale method however I did not know to use it only when looking at the var/

 

That works for me, thanks again.