Hi all I have an aggregateResult query which is pulling correctly into a visualforce page block table. All the numbers are have 0 digits right of decimal but the values display with one 0 to the right. Example: 510.0 instead of 510. Does anyone know how to fix this?

Also, can the numbers be displayed with the thousands (and more) commas?


Edited to show code sample

public List<AggregateResult> getAggregateList(){
            Parent_Custom_object__c TheCS = (Parent_Custom_object__c)sc.getRecord();
            List<AggregateResult> AggResults = new List <AggregateResult>();

         AggregateResult[] aggQuery = [select
     zone__c zone,
      from Custom_Child_object__c 
      where Parent_of_Custom_Child_object__c =:TheCS.id
      GROUP BY zone__c    

         for(AggregateResult QAR:aggQuery)

You'll want to use a wrapper if you need to convert the results in Apex:

public class Wrapper {
    public Integer totalAddedValue { get; set; }
    public Integer totalDelivered { get; set; }
    public String zone { get; set; }
    public Wrapper(AggregateResult result) {
        totalAddedValue = ((Decimal)result.get('TotalAddedValue')).intValue();
        totalDelivered = ((Decimal)result.get('TotalDelivered')).intValue();
        zone = (String)result.get('zone');

for(AggregateResult QAR:aggQuery) {
    AggResults.add(new Wrapper(QAR)); 

This will add a lot more Apex code, but eliminate the need for ROUND in the Visualforce markup.

Original Answer

Numeric values in an AggregateResult (aside from COUNT()) are Decimal values. Visualforce will show these with a decimal point by default. Use a function such as ROUND() in your code to remove it. Here's an example:

public class controller {
    public Decimal value { get; set; }
    public controller() {
        value = 5.0;

<apex:page controller="controller">
    Using ROUND: {!ROUND(value,0)}<br />
    Not Using ROUND: {!value}
| improve this answer | |
  • Is there a way to use ROUND in the aggregate query? – jaw999 Nov 14 '19 at 20:30
  • @jaw999 No. The alternative would be to write a wrapper class, transfer the data from the AggregateResult object to this wrapper (converting the values from Decimal to Integer), then display the wrapper values. – sfdcfox Nov 14 '19 at 20:33
  • I have added code for clarity. Not sure where to push the ROUND function – jaw999 Nov 14 '19 at 21:07
  • @jaw999 Added the Apex code version that you'd use. Also, P.S. the result of a query is never a null variable, so no need to do if(aggQuery != null). – sfdcfox Nov 14 '19 at 21:16
  • Thanks, I am getting an error of Method does not exist or incorrect signature: void add(CustomAdZoneTotals2.Wrapper) from the type List<AggregateResult> - an issue with how my wrapper is set? – jaw999 Nov 19 '19 at 15:47

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.