1

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.

1
  • i've done this through jquery
    – cropredy
    Commented Dec 3, 2015 at 16:59

1 Answer 1

5

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> 
1
  • Thanks Eric. We need to get the input from the user on the page and we are using apex:inputfield. Most of the times they may enter (and need) a few decimal points. Sometimes they need more so we need to dynamically render the value and trim the zeros.
    – Jorjani
    Commented Dec 3, 2015 at 16:49

You must log in to answer this question.

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