Find your content:

Search form

You are here

How to round outputFields of type=Decimal in a VF email template?

 
Share

I am working with visualforce template i am getting all decimal values in my mail but i want to round it in Max upto 2 decimals

      SubTotal  $90.0000
 Shipping & handling     $2.000
Grand Total(Excl.Tax)   $92.000
         Tax    $8.170
 Grand Total(Incl.Tax)  $100.1700

My Template Code

       <messaging:emailTemplate recipientType="Contact" relatedToType="Quote__c" subject="Your requested quote #{!relatedTo.Name}" >
      <messaging:htmlEmailBody>
                <apex:outputField value="{!relatedTo.Total_Price__c}"/>
              <apex:outputField value="{!relatedTo.Total_Shipping__c}"/>   
            <apex:outputField value="{!relatedTo.Gtotal__c}"/>
     </messaging:htmlEmailBody>

     </messaging:emailTemplate>

Attribution to: Sathya

Possible Suggestion/Solution #1

You have two options here:

  1. You can create formula fields to calculate and round the decimal values you need in the template. This has the benefit of letting you tweak the formula, and see the result until you have it just like you want it. It also has the added benefit of getting your complex formulas out of the view layer (the template) and into the model layer(object).
  2. Secondly, you can utilize inline functions to accomplish this within your template. In your case you'd want a merge expression something like this:

    {!ROUND(relatedTo.Total_Price__c,3)}

I prefer using #1, as it keeps the templates stupid simple and maintains a separation of concerns. But it's a trade off in dev speed.


Attribution to: Kevin P
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33098

My Block Status

My Block Content