0

I have a currency field that I multiply by .5 in my apex code.

This changes the data type to a Decimal.

I want to display on a visualforce email template the newly updated number as a currency.

Should I convert it back to a Currency? When I try to do this, I get an error saying that the type is not supported.

My end goal is to display the decimal in this format: $123,456.78

I want the dollar sign, commas, and 2 decimal places. I feel like there must be an easier way to do this rather then sending the decimal to the VFP and then manipulating the format with a outputText. Even with this way the dollar sign does not show.

Any advice?

All Different Attempts:

       <p><strong>Gross Sales Run Rate:</strong>
           {!strFormattedCurrency}
       </p>

        <p><strong>Gross Sales Run Rate:</strong>
            <apex:outputText value="{0, number, #,###.##}">
            $<apex:param value="{!strFormattedCurrency}" />
            </apex:outputText>
        </p>

        <p><strong>Gross Sales Run Rate:</strong>
            <apex:outputText value="{0, number, #,###.##}">
                $<apex:param value="{!annualRevenue}" />
            </apex:outputText>
        </p>

        <p><strong>Gross Sales Run Rate:</strong>
            <apex:outputText value="${0, number, 00.00}">
                <apex:param value="{!annualRevenue}" />
            </apex:outputText>
        </p>

        <p><strong>Gross Sales Run Rate:</strong>
             <apex:outputText value="{0, number, 00.00}">
             <apex:param value="{!strFormattedCurrency}" />
             </apex:outputText>
        </p>

APEX:

public class BrokerApprovalEmailTemplate {

public Decimal annualRevenue {get;set;}
public String strFormattedCurrency {get;set;}

public void init() {
    Decimal crAnnualRevenue;
    ....
    if(creview.Half_Revenue__c == true && (creview.SIC_Code__c == '5411' || creview.SIC_Code__c == '5541')) {
       crAnnualRevenue = creview.Annual_Revenue__c * 0.50;
    }
    else if(creview.Half_Revenue__c == true){
        crAnnualRevenue = creview.Annual_Revenue__c * 0.75;
    }
    else {
        crAnnualRevenue = creview.Annual_Revenue__c;
    }
        annualRevenue = crAnnualRevenue.setScale(2, RoundingMode.HALF_UP);
        strFormattedCurrency = '$' + string.valueOf(annualRevenue);

1 Answer 1

2

Why not just output the field?

<apex:outputField value="{!record.Annual_Revenue__c}" />

In your controller, it would be as simple as:

   creview.Annual_Revenue__c *= 0.50;
   ...
   creview.Annual_Revenue__c = creview.Annual_Revenue__c.setScale(2, RoundingMode.HALF_UP);

This gives you automatic currency formatting without having to deal with any extra code.

You must log in to answer this question.

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