1

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>
5
  • Have a look at the documentation for VF functions ( salesforce.com/us/developer/docs/pages/Content/… ) and try to answer your own question. Apr 18, 2014 at 7:54
  • @SamuelDeRycke <apex:outputField value="{!ROUND(relatedTo.Total_Price__c,2)}"/ i tried like this but it showing Error: Syntax error. Missing ')'
    – Sathya
    Apr 18, 2014 at 8:10
  • Then, in one of the lines you may have forgotten to put a ")" ? Apr 18, 2014 at 8:14
  • @SamuelDeRycke value for <apex:outputField value="{ROUND(!relatedTo.Total_Price__c,3)}"/> <apex:outputField> is not a dynamic binding! in this case this errpr
    – Sathya
    Apr 18, 2014 at 8:19
  • Sathya - you are misunderstanding how expressions work in VF - the correct syntax is as Samuel De Rycke stated - <apex:outputField value="{!ROUND(relatedTo.Total_Price__c,3)}"/> The {! appears at the beginning of the expression and you don't embed {! again in the expression
    – cropredy
    Apr 18, 2014 at 16:01

1 Answer 1

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.

1
  • <apex:outputField value="{!ROUND(relatedTo.Total_Price__c,3)}"/> it showing Syntax missing in )' <apex:outputField value="{!relatedTo.Total_Price__c}"/> it is working fine.
    – Sathya
    Apr 18, 2014 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .