You need to sign in to do that
Don't have an account?
How to Ensure 2 Decimal places are displayed for an apex:inputtext value.
Hello,
I have an apex form with inputText fields. The values are decimals. The following behaviour occurs.
If the value is 12345 it displays on the web form as 12345.0
If the vaue is 12345.23 it displays as 12345.23
if the value is 12345.5 it displays as 12345.5
What I require is that 2 decimal places are always displayed. E.G. the above should display as 12345.00, 12345.23 and 12345.50
I've tried a couple of ways to ensure this same formatting will apply to all values but they have all failed.
- In my controller to manipulate the value and always make it double decimaled. This failed as it still truncated to one decimal being displayed on my visualforce page.
- To try to format it on the visualforce page itself (Decimal functions such as http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm I could not seem to use this in the page as it saved with an error); To change it using suggestions similar to the following for apex:outputTexts http://cloudjedi.wordpress.com/2011/08/17/formatting-numbers-or-dates-with-visualforce/ http://salesforce.stackexchange.com/questions/318/what-is-a-concise-function-that-formats-a-string-decimal-into-a-currency-forma but these did not seem to work for an inputText.
I've noted the following ideas discussion http://success.salesforce.com/ideaView?id=08730000000Bqq9 and also the following formula field blog postings but would an if statement similar to that in the formula field be required in an inline if statement?
Is there no easy way to ensure this formatting displays correctky?
Thanks in advance for any help. Appreciated as always!
<apex:outputText value="{0, number, 00.00}">
<apex:param value="{!Account.AnnualRevenue}" />
</apex:outputText>
Refer this :
http://blog.wdcigroup.net/2012/09/salesforce-apex-data-formatting-in-visualforce-using-outputtext-2/
Hi Laxman,
Thanks for your suggestion. I've noted the apex:outputText examples peviously but it's an apex:inputText I require it for. Do know if a similar setup can be done for apex input texts? I could not get it to work.
Thanks,
Have you tried this :
Contoller :
public decimal test{set;get;}
Public example() {
test = 4555.222222;
test = test.setScale(2);
}
Visual force :
<apex:inputText value="{!test}" />
Hi Laxman,
Yes tried a similar process already and after ensuring the parameter has 2 decimal places in my controller it still truncated to 50.0 for examle if previously 50.00 in my controller.
Thanks for any help.