function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SXSX 

How to Removing Trailing Zeros in outputField

I am trying to round the decimal places that are being displayed in an outputField to remove trailing zeros. The custom field that I am trying to display is set to be a number with 7 decimal places. There are cases though where not all 7 decimal places will be used, so I want to strip away trailing zeros.


Example: If I had 10.0001000 I want it to display as 10.0001 on my Visualforce page.

 

I tried doing something like this:

 

<apex:outputField value="{0}">
   <apex:param value="{!ROUND(customField__c, number)}" />
</apex:outputField>

 This returned an error value for <apex:outputField> is not a dynamic binding!

 

If I change it to an outputText it works, but I need this field to be based on user locale which is why I was using an outputField.

 

Thanks in advance!

Geetha ReddyGeetha Reddy

HI

 

Try this .


<apex:outputText value="{0, number, ###,###,###,##0.00}"> <apex:param value="{!a.customField__c}"/>

</apex:outputText>

 

Let me know if any issues.

SXSX

Thanks I ended up using something like this to format my field based on the user locale because the outputText rounds of trailing zeros.

 

<apex:outputText value="{!SUBSTITUTE(TEXT(customField__c), '.', ',')}"/>

 

I tried to do something similar to this for the inputText field

<apex:inputText value="{!SUBSTITUTE(TEXT(customField__c), '.', ',')}"/>

 but I get a syntax error.

 

Is it possible to format data inside of an inputText field?


Thanks!

U JayU Jay
<apex:inputText value="{!SUBSTITUTE(TEXT(a.customField__c), '.', ',')}"/> works .
U JayU Jay
I have another issue :)
<apex:outputText value="{!SUBSTITUTE(TEXT(additionalCost.List_Price__c)+'0','.',',')}"
Here removed trailing zeroes automatically, when converted to text.
Can i maintain it within the page itself??