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
mdinatalemdinatale 

Round like php does

Im trying to round a decimal number just like php does but im having different outcomes with different numbers. I just need the standard round function like php. Ive tried these. Thanks foryour help

 

bpm = math.ceil(bpm);
bpm = math.round(bpm);
bpm = bpm.setscale(2);
bpm = math.roundToLong(bpm);

 

SeAlVaSeAlVa

I think that you should use setScale, but providing 2 parameters, the scale and the type of round you want to perform,  (System.RoundingMode.HALF_UP I believe, if not, use the following link )

 

it would be something like the following

bpm = bpm.setScale(2,System.RoundingMode.HALF_UP);

 (IF bpm is a decimal type)

 

Regards

Chamil MadusankaChamil Madusanka

Refer following links. It will be helpful for your requirement

 

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

 

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

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.