0

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 Dec 3 '15 at 16:59
4

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, teeth's, 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 Dec 3 '15 at 16:49

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.