You need to sign in to do that
Don't have an account?
snolbu2
Sum function can't display decimal space
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
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
But I tried and compile failed.
Basically, SOQL Sum display Number without decimal space