+ Start a Discussion
Rick MacGuiganRick MacGuigan 

Convert negative number to positive

This should be simple but appears difficult. My visual force page displays negative values retrieved from SOQL query in the controller. I need that number to be positive and thought I could simply use ABS to do this on either the VisualdForce page or controller. 

How can I do this ? field is PAID_LOSS__c

VF Page:
<apex:dataTable id="dt2c" styleClass="alldatatables" headerClass="alldatacols" columnClasses="alldatacols" rowClasses="alldatarows"  value="{!PriorYRcontractSectionList}" var="pyr" rules="all" cellpadding="5"  >
...
<apex:column value="{!pyr.PAID_LOSS__c}" headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }"/>
Controller: 
private List<MR_Contracts__c> queryPriorYRcontractsectionById(List<String> contractIds, string ContractYear) {
   //used to display Contract Section Data based on user selected submissions for the multiselect field.
   //Filter by 
  List<MR_Contracts__c> PriorYRcontractsectionById = [    
    //return [
      SELECT
        Id
        ,Name
        ,ULTIMATE_PREMIUM__c
        ,PAID_LOSS__c
        ,ACR__c
        ,ULTIMATE_LOSS__c
        ,Ultimate_Loss_Ratio__c
        ,F_DETAIL_COMMISSION__c
        ,F_DETAIL_BROKERAGE__c
        ,ULT_OVERHEAD_EXCL_CATS__c
        ,ULT_CR_ACCT_OH__c
        ,ULT_CR_ACCT_EXCL_OH__c
        ,ITD_CR_INCL_ACCT_OH__c
        ,ITD_CR_EXCL_ACCT_OH__c


       FROM
        MR_Contracts__c
      WHERE
        ContractSubmissionRef__c IN :contractIds   
      ORDER BY Name DESC
    ];

      this.allNulls_PAID_LOSS_dt2c= false; 
      this.allNulls_ACR_dt2c= false; 
      this.allNulls_ULTIMATE_LOSS_dt2c= false; 
      this.allNulls_Ultimate_Loss_Ratio_dt2c= false; 
      this.allNulls_F_DETAIL_COMMISSION_dt2c= false; 
      this.allNulls_F_DETAIL_BROKERAGE_dt2c= false; 
      this.allNulls_ULT_OVERHEAD_EXCL_CATS_dt2c= false; 
      this.allNulls_ULT_CR_ACCT_OH_dt2c= false; 
      this.allNulls_ULT_CR_ACCT_EXCL_OH_dt2c= false; 
      this.allNulls_ITD_CR_INCL_ACCT_OH_dt2c= false; 
      this.allNulls_ITD_CR_EXCL_ACCT_OH_dt2c= false; 
      
    for (MR_Contracts__c dt2cResult : PriorYRcontractsectionById) {
    //special considerations: Need to summ up all column values and test if total <- 0 to ensure all columns contain no data. Used to render column in dataTables.
    
      if (dt2cResult.PAID_LOSS__c > 0) {allNulls_PAID_LOSS_dt2c = true;}  
      if (dt2cResult.ACR__c > 0) {allNulls_ACR_dt2c = true;}  
      if (dt2cResult.ULTIMATE_LOSS__c > 0) {allNulls_ULTIMATE_LOSS_dt2c = true;}  
      if (dt2cResult.Ultimate_Loss_Ratio__c > 0) {allNulls_Ultimate_Loss_Ratio_dt2c = true;}  
      if (dt2cResult.F_DETAIL_COMMISSION__c > 0) {allNulls_F_DETAIL_COMMISSION_dt2c = true;}  
      if (dt2cResult.F_DETAIL_BROKERAGE__c > 0) {allNulls_F_DETAIL_BROKERAGE_dt2c = true;}  
      if (dt2cResult.ULT_OVERHEAD_EXCL_CATS__c > 0) {allNulls_ULT_OVERHEAD_EXCL_CATS_dt2c = true;}  
      if (dt2cResult.ULT_CR_ACCT_OH__c > 0) {allNulls_ULT_CR_ACCT_OH_dt2c = true;}  
      if (dt2cResult.ULT_CR_ACCT_EXCL_OH__c > 0) {allNulls_ULT_CR_ACCT_EXCL_OH_dt2c = true;}  
      if (dt2cResult.ITD_CR_INCL_ACCT_OH__c > 0) {allNulls_ITD_CR_INCL_ACCT_OH_dt2c = true;}  
      if (dt2cResult.ITD_CR_EXCL_ACCT_OH__c > 0) {allNulls_ITD_CR_EXCL_ACCT_OH_dt2c = true;}  

    }

  return PriorYRcontractsectionById;   
    
  }



 
Best Answer chosen by Rick MacGuigan
Rick MacGuiganRick MacGuigan
This is the final fix. 
<apex:column headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }">
  <apex:outputText value="{0, number, #,##0}">
   <apex:param value="{!ABS(pyr.PAID_LOSS__c)}" />
  </apex:outputText>
</apex:column>

 

All Answers

Amit Singh 1Amit Singh 1
Rick,

Try with below code for VF page.
<apex:dataTable id="dt2c" styleClass="alldatatables" headerClass="alldatacols" columnClasses="alldatacols" rowClasses="alldatarows"  value="{!PriorYRcontractSectionList}" var="pyr" rules="all" cellpadding="5"  >
...
<apex:column value="{!ABS(pyr.PAID_LOSS__c}" headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }"/>
It will do the trick :)

Thanks,
Amit Singh.
Rick MacGuiganRick MacGuigan
Thanks for your response Amit. However, neither of the syntax below works. 
Syntax error. Missing ')'
Error is in expression '{!ABS(pyr}' in component <apex:dataTable> in page prod_uw_accountsummary
 
<apex:column value="{!ABS(pyr.PAID_LOSS__c)}" headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }"/>
Error: Syntax error. Missing ')'
<apex:column value="{!ABS(pyr.PAID_LOSS__c}" headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }"/>


 
Amit Singh 1Amit Singh 1
Rick,

Try below code and make Sure PAID_LOSS__c is Number filed.
<apex:column headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }">
       <apex:outputText> 
             {!ABS(pyr.PAID_LOSS__c}
        </apex:outputText>
</apex:column>
Hope this will help. Let me know :)

Thanks,
Amit Singh.
 
Rick MacGuiganRick MacGuigan
Amit, still needed to cloose out the left paren even with this. 

Using the outputText embedded in the column oriduces a positve number that lack the thousand seperator.  Why can't I use the ABS function in the value  instead of having to output it as text. This field type is a double. 
User-added image

related code:
... this is not acceptin the ABS function. 
<apex:column value="{!pyr.PAID_LOSS__c}" headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }"/>

.... this produced the positive number. Need to close out the left paren.                                   
<apex:column headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }">
       <apex:outputText > 
             {!ABS(pyr.PAID_LOSS__c)}
        </apex:outputText>
</apex:column>




 
Rick MacGuiganRick MacGuigan
This is the final fix. 
<apex:column headerValue="Ttl Rprd Loss" rendered="{! (allNulls_PAID_LOSS_dt2c || hidecols) }">
  <apex:outputText value="{0, number, #,##0}">
   <apex:param value="{!ABS(pyr.PAID_LOSS__c)}" />
  </apex:outputText>
</apex:column>

 
This was selected as the best answer