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
wenchun zgwenchun zg 

bug of decimal round up?

I'm using Decimal round up, but it seems it always give me the round-down integer but not the up-integer.

Decimal pages = this.processedNum/pageSize; 
          
this.totalpages = (Integer)pages.round(System.RoundingMode.CEILING);
processedNum = 56;
pageSize = 10;

The excepted totalpages should be 6, but it returns 5..

Any wrong with my code?

Thanks

Best Answer chosen by wenchun zg
CheyneCheyne
This is probably happening because this.processedNum and pageSize are both defined as integers, so the first line is doing integer division, meaning it is discarding the remainder. So, 56 / 10 = 5. Try casting one of the numbers as a decimal, by changing the first line to 

Decimal pages = Decimal.valueOf(this.processedNum) / pageSize