1

I have the following code in visualforce:

<apex:variable value="{!Opportunity.Amount-Opportunity.Descuento_Autorizado__c}" var="descontado"/>
   {!IF(Opportunity.CurrencyIsoCode=="USD",
   <apex:outputText value="${0, number, ###,##0.00}">
        <apex:param value="{!descontado}"/>
        </apex:outputText>,
        <apex:outputText value="Q{0, number, ###,##0.00}">
        <apex:param value="{!descontado}"/>
        </apex:outputText>)}

I'm 99% sure this isn't even the correct way to do it but just so you have the idea of what I'm trying to do. I'm trying to show a different currency symbols using depending on the value of the currency on the opportunity. Is there a way to achieve this?

2 Answers 2

0

You're almost there. For complex logic, you can use an apex:outputPanel to determine whether something is rendered.

e.g.

<apex:variable value="{!Opportunity.Amount-Opportunity.Descuento_Autorizado__c}" var="descontado"/>

<apex:outputPanel rendered="{!Opportunity.CurrencyIsoCode = 'USD'}" layout="none">
    <apex:outputText value="${0, number, ###,##0.00}">
        <apex:param value="{!descontado}"/>
    </apex:outputText>
</apex:outputPanel>

<apex:outputPanel rendered="{!Opportunity.CurrencyIsoCode != 'USD'}" layout="none">
    <apex:outputText value="Q{0, number, ###,##0.00}">
        <apex:param value="{!descontado}"/>
    </apex:outputText>
</apex:outputPanel>

By adding layout="none" to the apex:outputPanel, you ensure no wrapping div/span is added to the page.

Or, even simpler you can add the condition to the apex:outputText element:

<apex:outputText value="{!IF(Opportunity.CurrencyIsoCode = 'USD', '$', 'Q')}{0, number, ###,##0.00}">
    <apex:param value="{!descontado}"/>
</apex:outputText>
1
2

You do not need separate rendering for currency. Following format automatically displays currency symbol.

 <apex:outputText value="{0, number, currency}">

Code:

<apex:variable value="{!Opportunity.Amount-Opportunity.Descuento_Autorizado__c}" var="descontado"/>

<apex:outputPanel layout="none">
    <apex:outputText value="{0, number, currency}">
        <apex:param value="{!descontado}"/>
    </apex:outputText>
</apex:outputPanel>

Sample output:

$345,670.00

1
  • Both answers are great! The only issue is that in some cases I'm using numbers and showing them as currency so the format won't work. Still great thanks! Commented Aug 16, 2017 at 3:50

You must log in to answer this question.

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