[SalesForce] Trim/remove trailing zeros from decimal apex:inputfield

We have a decimal apex:inputfield that supports up to 12 decimal points; however most of our cases will not use more than 4-5 decimal points and we don't want to clutter the page with extra zeros. What is the simplest solution to trim the trailing zeros? I know decimal.stripTrailingZeros() does that in apex but when the field is being shown on the page, it still show the zeros. The only other way we can think of is probably Javascript.

Best Answer

You can use the Java Message Format that is built into the outputText tag:

https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html

It would go like this (having a number in the tens, tenths, and hundredths at all times (0):

<apex:outputText value="{0,number,#,##0.00}">
     <apex:param value="{!FIELDAPINAME}"/>
</apex:outputText> 
Related Topic