15

is there a way to pass a string to the <apex:outputText> so that it can be formatted as a currency or percent value?

Here's what I have inside a column of my visual force table:

<apex:outputText value="{0, number, currecny}">
<apex:param value="{!row.values[1]}" />
</apex:outputText

this gives me an error at runtime (when the visual force page loads), which I think may be some kind of type mismatch, where <apex:outputText> is expecting a Decimal or number but I am passing a string.

This is the error at runtime:

The value attribute on is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.

Thanks

14

The problem was you misspelled currency. This works fine and avoids hard coding the currency symbol:

<apex:outputText value="{0, Number, Currency}">

9

From my comment:

<apex:outputText value="${0, number, ###,###,##0.00}"> works as well. The hashes display numbers in that position if they exist. So it will display $3.14 instead of $000,003.14 as in the example using ${0, number, 000,000.00}

7

You need to use <apex param> along with <apex:outputText> by specifying the proper parameters for it to be output in. Here's an example from the VF Developer's Guide:

<!-- For this example to render properly, you must associate the Visualforce page
with a valid account record in the URL.
For example, if 001D000000IeChM is the account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001D000000IeChM
See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->

<apex:page standardController="Account">
It is worth:
<apex:outputText value="{0, number, 000,000.00}">
<apex:param value="{!Account.AnnualRevenue}" />
</apex:outputText>
</apex:page>

This would render as

It is worth: 500,000,000.00

Were I doing this, I'd be adding the currency symbol in with the outputText value as below:

<apex:outputText value="$&nbsp{0, number, 000,000.00}">

This would render as

It is worth: $500,000,000.00
  • I'm not really sure what advice you are supplying that I do not already know. I am using both of the tags. – JSF Jul 22 '14 at 17:19
  • 1
    It turns out I have been able to answer my own question. As I thought, apex:param cannot take a string, as it expects a number and will not do any sort of type conversion, so a string wrapper class will not work with this. Instead I created a generic object wrapper class and it works wonderfully. Will update the answer when stack exchange allows it. – JSF Jul 22 '14 at 17:47
  • 1
    I suspect a String is valid when the output format is a String, in this case the output format clearly specifies a number hence the mismatch. That said, the error message could be more useful! – Matt Lacey Sep 24 '14 at 22:03
  • 4
    For completeness, <apex:outputText value="${0, number, ###,###,##0.00}"> works as well. The hashtags display numbers in that position if they exist. So it will display $3.14 instead of $000,003.14 as in the example using ${0, number, 000,000.00}. – Scott Pelak Nov 24 '15 at 18:11
  • 1
    @ʞɐʃǝԀʇʇoɔS, You should post your comment as answer to this question. It is very helpful. Thanks! – javanoob Mar 15 '16 at 2:45
1

The Best Solution for the above problem is:

<apex:outputText label="NRR" value="{0,number}">
{! Opportunity.CurrencyIsoCode} &nbsp;
<apex:param value="{! Opportunity.NRR__c}" />
</apex:outputText>

This is give you the Currency (CurrencyIsoCode) as well as the value (in proper format) if it exists in the field value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.