• snolbu2
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all
I have a problem with SUM (aggregate function).

I summed currency Field(16, 2).
I expected 2 decimal spaces, but The result was just Long.
It's been occuring every currency field in Developer Console, Apex Code, Salesforce.schema
How Can I fix it ?

1. Field : M1_AR__c (Currency 16,2)
2. Query & Apex Code
   AggregateResult[] ar = Database.query(' SELECT Sum(M1_AR__c) , Sum(M1_Fixed__c) '+
                                                                            ' FROM KR_Invoice_New__c WHERE Batch_Month__c = \'2014-05\' '+
                                                                            ' AND M1_Arrear__c > 180 AND M1_Arrear__c < 361 '+
                                                                            ' AND Business_Closure__c <> \'closed business & Collection agency\' ');
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + ar[0].get('expr0'));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + String.valueOf(ar[0].get('expr0')));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + Decimal.valueOf(String.valueOf(ar[0].get('expr0'))));

3. Return Value
  - Expected Value :      1788272509.32
  - Real Return Value : 1788272509

4. Each Currency Value
  - Each Currency Value is stored with decimal space 2
  - They was summed => 1788272509.32
User-added image
Hi all
I have a problem with SUM (aggregate function).

I summed currency Field(16, 2).
I expected 2 decimal spaces, but The result was just Long.
It's been occuring every currency field in Developer Console, Apex Code, Salesforce.schema
How Can I fix it ?

1. Field : M1_AR__c (Currency 16,2)
2. Query & Apex Code
   AggregateResult[] ar = Database.query(' SELECT Sum(M1_AR__c) , Sum(M1_Fixed__c) '+
                                                                            ' FROM KR_Invoice_New__c WHERE Batch_Month__c = \'2014-05\' '+
                                                                            ' AND M1_Arrear__c > 180 AND M1_Arrear__c < 361 '+
                                                                            ' AND Business_Closure__c <> \'closed business & Collection agency\' ');
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + ar[0].get('expr0'));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + String.valueOf(ar[0].get('expr0')));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + Decimal.valueOf(String.valueOf(ar[0].get('expr0'))));

3. Return Value
  - Expected Value :      1788272509.32
  - Real Return Value : 1788272509

4. Each Currency Value
  - Each Currency Value is stored with decimal space 2
  - They was summed => 1788272509.32
User-added image